Reputation: 1591
The root one:
a.xsd
Which imports | includes:
<xsd:import schemaLocation="b.xsd"/>
<xsd:include schemaLocation="c.xsd"/>
I know there are lots of online tools (validator) can have one XML file and a single one .xsd file as input and run the validation.
Considering the "import" and "include" are involved, what are the options to validate an XML file by just specify a single .xsd file?
Which GUI tool (a free one) can be used to do a quick validation? How to implement in code of any one of the languages Java/C#/C++/Python?
Thank you in advance
Upvotes: 4
Views: 2215
Reputation: 1591
The answer is simple: put following files in the same folder.
I've wrote a Validator.py with following contents:
import sys
from lxml import etree
doc = etree.parse(sys.argv[1])
xmlschema_doc = etree.parse('a.xsd')
xmlschema = etree.XMLSchema(xmlschema_doc)
if xmlschema(doc):
print 'Success!'
else:
print 'Invalid!'
xmlschema.assertValid(doc)
raw_input()
Execute in command line (Windows):
python Validator.py aParser.xml
Upvotes: 1