xsd 在 python 中解析

xsd parsing in python

我有一个 xdr 文件,其格式描述为 xsd。所以我需要先解析xsd文件。是否有 python 工具可以解析 xsd 并提供各个字段及其类型。

我正在尝试解析的 xsd 文件示例如下:http://mibs.cablelabs.com/namespaces/DOCSIS/3.0/xsd/ipdr/DOCSIS-SAMIS-TYPE-1/DOCSIS-SAMIS-TYPE-1_3.5.1-A.1.xsd

我想你可能想看看这个人,首先:

https://pypi.org/project/xmlschema/

我自己以前从未使用过它,但它看起来很强大而且很棒。

注意这个功能:

Decoding of XML data into Python data and to JSON

如示例中所述:

Using a schema you can also decode the XML documents to nested dictionaries, with values that match to the data types declared by the schema.

我想你可能想试一试那个库。

现在,关于熟悉架构的最佳方法,正如我假设的那样,这是您的目标,为什么不尝试使用 XML 编辑器(例如 oXygen)生成示例实例,然后使用上面的内容看看里面都有什么?

您也可以试试:

https://pypi.org/project/generateDS/

希望对您有所帮助!