Python create xml from xsd

两盒软妹~` 提交于 2020-04-12 09:41:32

问题


I am new with python and need to implement an interface to an accounting tool. I received some XSD Files which describes the interface.

What is the easiest way to generate the XML according to the XSD? Is there any module I can use?

Do I have to create the XML all by myself and I can use the XSD just to verify it? How do I best proceed?


回答1:


I think, generateDS is the solution to your problem. Starting from chapter 5, the command

python generateDS.py -o people.py -s peoplesubs.py people.xsd

reads the XSD file and creates several classes and subclasses. 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

import people
rootObject = people.parse('people.xml')

within the code. More information is given in chapter 12. The aforementioned classes also provide methods to export data as an XML format. The level of documentation is good and it is highly suggested to use this for any future project.



来源:https://stackoverflow.com/questions/48928973/python-create-xml-from-xsd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!