I have a XML file with the following content:
<example>
<firstNode>
<someInfo>Hello</someInfo>
</firstNode>
<secondNode>
<myFlagColors>
<using>RED</using>
<using>WHITE</using>
<using>BLUE</using>
</myFlagColors>
</secondNode>
</example>
I have to check that every node <using>XYZ</using>
has a value (like XYZ) coming from another XML like this one:
<colorCatalog>
<color>WHITE</color>
<color>BLACK</color>
<color>RED</color>
<color>GREEN</color>
<color>BLUE</color>
<color>YELLOW</color>
<color>PINK</color>
<color>ORANGE</color>
<color>CYAN</color>
</colorCatalog>
I don´t like my current implementation made with java: Convert every XML in a java Bean (using jaxb) and then use an iterator to check if the value in the first bean in in the array of values of the second object.
My question: Is it possible to do this just by using xsd files? or any other way simpler than pure programming?
XML Schema Approach
If you can combine the XML documents then you could create an XSD that has a keyRef relationship between the 2 elements.
Validating the document against the schema would then highlight any errors.
If you can't combine the XML files easily then you could use xinclude (as long as your XSD parser supports it). Xerces for example supports it.