java XML parsing and ignoring elements not in the XSD schema



I have a requirement in java to parse XML and skipping any tag not defined in the XSD schema. in other words only elements in Schema are parsed other elements are ignored without through a validation error. Validation error will exists only if the element found in the XSD is of different data type ...etc


** very simple schema:-** root contains x,y,z all strings.


example 1



<root>
<x>anyvalue</x>
<y>anyvalue</y>
<z>anyvalue</z>
</root>


result 1



<root>
<x>anyvalue</x>
<y>anyvalue</y>
<z>anyvalue</z>
</root>


example 2:-



<root>
<x>anyvalue</x>
<notdefined>anyvalue</notdefined>
<z>anyvalue</z>
</root>


result 2:-



<root>
<x>anyvalue</x>
<z>anyvalue</z>
</root>


example 3:-



<root>
<notdefined>anyvalue</notdefined>
<x>anyvalue</x>
<z>anyvalue</z>
</root>


result 3:-



<root>
<x>anyvalue</x>
<z>anyvalue</z>
</root>

No comments:

Post a Comment