I've went on an on searching for something that could help me, but with no success, so I'm turning to you.
I'm writing a code in Java that need to validate XMLs against given dynamic schemas. I'm given 2 XSDs that one references an element from the other one. The requirement is that only XMLs which are using the elements in the root XSD will be valid. An example will clear things up.
Example of XSDs
The first one:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://root/beer"
xmlns="http://root/beer" xmlns:chl="http://child/earth"
xmlns:xs="http://ift.tt/tphNwY">
<xs:import namespace="http://child/earth" schemaLocation="testing_child.xsd"/>
<xs:element name="head">
<xs:complexType>
<xs:sequence>
<xs:element ref="chl:banana"/>
</xs:sequence>
</xs:complexType>
</xs:element>
The Second one:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://child/earth"
xmlns="http://child/earth" elementFormDefault="qualified"
xmlns:xs="http://ift.tt/tphNwY">
<xs:element name="banana">
<xs:complexType>
<xs:sequence>
<xs:element name="leaf" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Now, I want that the following XML will be valid:
<head xmlns="http://root/beer">
<banana xmlns="http://child/earth">
<leaf>yo</leaf>
</banana>
</head>
BUT (and that's the tricky bit), this one won't:
<banana xmlns="http://child/earth">
<leaf>yo</leaf>
</banana>
I tried using Validator with SAX and DOM, using LSResourceResolver and without, but came with the same result - both XMLs are valid and not only the parent(/root) one.... I can't use JAXB because I can't build classes out of the XSDs (they are kept in files in the fs). And no, I can't change the XSDs either.
If you know of a way / have done something similar in the past and could help me, I'll really appreciate it.
Thanks
Tiada ulasan:
Catat Ulasan