java - One XSD for both whole document and fragment? -
i wish create grammar able validate both full xml document , fragment of it.
i have set of documents aggregate in “batch”. each document has set of meta-data:
<batch> <document> <metadata1 /> <metadata2 /> <metadata3 /> </document> <document> <metadata1 /> <metadata2 /> <metadata3 /> </document> </batch>
my springbatch process splits batch in documents (with staxeventitemreader) wish validate sub xml representing single document:
<document> <metadata1 /> <metadata2 /> <metadata3 /> </document>
i read here can’t use partial xsd validate xml.
however, is there way, while avoiding duplication, validate 2 xsds, 1 validate fragment, , other validate batch?
you can achieve goal single xsd specifying multiple possible root elements:
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:element name="batch"> <xs:complextype> <xs:sequence> <xs:element ref="document" maxoccurs="unbounded"/> </xs:sequence> </xs:complextype> </xs:element> <xs:element name="document"> <xs:complextype> <xs:sequence> <xs:element name="metadata1" type="xs:string" /> <xs:element name="metadata2" type="xs:string" /> <xs:element name="metadata3" type="xs:string" /> </xs:sequence> </xs:complextype> </xs:element> </xs:schema>
this way documents may have either batch
or document
root element, , there no definition duplication.
Comments
Post a Comment