[英]read XSD and create corresponding XML
I have spent hours looking for this but I couldn't find any answer... I have an XSD file (given by another source) and I am trying to create an XML file that complies with that.我花了几个小时寻找这个,但我找不到任何答案......我有一个 XSD 文件(由另一个来源提供),我正在尝试创建一个符合该文件的 XML 文件。 I have all the data ready to data structures.
我已经准备好数据结构的所有数据。 All I need to do is to export data as XML BY FOLLOWING the XSD.
我需要做的就是通过遵循 XSD 将数据导出为 XML。 Is that possible?
那可能吗?
I am not looking to export XSD to XML, neither to validate XML nor to parse XML.我不希望将 XSD 导出到 XML,既不验证 XML 也不解析 XML。 I start from scratch, I read XSD and based on that I am trying to create XML by mapping my data structures to the allowed elements from XSD.
我从头开始,阅读 XSD,并基于此尝试通过将我的数据结构映射到 XSD 中允许的元素来创建 XML。
Conceptually, it seems doable.... however, I haven't found any answer yet.从概念上讲,这似乎是可行的……但是,我还没有找到任何答案。 Any ideas and suggestions (preferably in Python 2) are more than welcome.
任何想法和建议(最好在 Python 2 中)都非常受欢迎。
I sorted it out and I reply to myself for other's benefit.我整理了一下,为了别人的利益,我回复了自己。
As nicely proposed, generateDS is the solution to the problem.正如很好地提出的那样, generateDS是问题的解决方案。 Starting from chapter 5, the command
从第 5 章开始,命令
python generateDS.py -o people.py -s peoplesubs.py people.xsd
reads the XSD file and creates several classes and subclasses.读取 XSD 文件并创建多个类和子类。 It generates many data structures and getters and setters for accessing and using data :) If there is any XML file that complies with that XSD, it can be read straight away by using
它生成许多数据结构以及用于访问和使用数据的 getter 和 setter :) 如果有任何符合该 XSD 的 XML 文件,它可以通过使用直接读取
import people
rootObject = people.parse('people.xml')
whithin the code.在代码中。 More information is given in chapter 12. The aforementioned classes also provide methods to export data as an XML format.
第 12 章提供了更多信息。上述类还提供了将数据导出为 XML 格式的方法。 The level of documentation is good and it is highly suggested to use this for any future project.
文档水平很好,强烈建议在未来的任何项目中使用它。
Have fun, C.玩得开心,C。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.