如何使用XSD导入/包含其他XSD文件来验证xml ?

时间:2022-05-03 22:31:16

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.

我知道有很多在线工具(验证器)可以有一个XML文件和一个.xsd文件作为输入并运行验证。

Considering the "import" and "include" are involved, what are the options to validate an XML file by just specify a single .xsd file?

考虑到涉及到“导入”和“包含”,通过指定一个.xsd文件来验证XML文件的选项有哪些?

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?

哪个GUI工具(一个免费的)可以用于快速验证?如何在任何一种语言的代码中实现Java/ c# / c++ /Python?

Thank you in advance

提前谢谢你

1 个解决方案

#1


-1  

  1. The answer is simple: put following files in the same folder.

    答案很简单:将以下文件放在同一个文件夹中。

    • a.xsd
    • a.xsd
    • b.xsd
    • b.xsd
    • c.xsd
    • c.xsd
  2. I've wrote a Validator.py with following contents:

    我写了一个验证器。py和以下内容:

    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()
    
  3. Execute in command line (Windows):

    执行命令行(窗口):

    python Validator.py aParser.xml
    

#1


-1  

  1. The answer is simple: put following files in the same folder.

    答案很简单:将以下文件放在同一个文件夹中。

    • a.xsd
    • a.xsd
    • b.xsd
    • b.xsd
    • c.xsd
    • c.xsd
  2. I've wrote a Validator.py with following contents:

    我写了一个验证器。py和以下内容:

    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()
    
  3. Execute in command line (Windows):

    执行命令行(窗口):

    python Validator.py aParser.xml