简体   繁体   中英

How to parse xsd and create XML's from it with python?

I'm very begginer with python and I have task to parse xsd schema to python code, fill nodes with values and create final XML file from it. Is it possible with generateDS tool? I can't find clear anwser in documentation. Maybe theres another way to do it? Thanks for anwsers

This question is rather broad to answer in a single post. So I will give the correct method that you would need to follow to solve the problem.

Firstly, XSD is the schema definition of an XML instance, essentially the rules of the XML file. Parsing is not the right word to use here, instead creating an XML instance from a XSD would be a better sound.

You would need to use pyxb to process your xml schema definitions. See this , its a good walkthrough. You can also use this library to do the same job.

Now that your definitions are processed you can then insert/delete values from your XML instance. See this for an example.

Maybe someone in future will have same problem as I had, so there's a tip: to create objects from Schema use generateDS tool, it's a way easier to use rather than pyxb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM