Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Python accessible tools can you use to generate XSD from an XML document?

I'm looking for a tool that will play nicely with Python. Except for my Python requirement, my question is the same as this one:

"I am looking for a tool which will take an XML instance document and output a corresponding XSD schema."

like image 537
chobok Avatar asked Oct 18 '11 06:10

chobok


3 Answers

According to the PyCharm docs, PyCharm has a facility for this. This is not exactly accessible by a program as an API. You are probably better off using XML Schema Learner as a separate program since it is a command line program (subprocess friendly!).

like image 118
microe14 Avatar answered Oct 11 '22 01:10

microe14


Are you looking for something like pyxsd? (primarily used for validation against a schema) Or maybe PyXB? (can generate classes based on xml) Otherwise, I don't think there's a tool [yet] that will generate the schema from within Python. Can you do it on demand using something like xsd.exe? Does it have to be programmatic/repeatable?

like image 34
end-user Avatar answered Oct 11 '22 03:10

end-user


Currently, there is no module that will run within your python program and do this conversion. But I see the problem of creating a XSD schema from XML as a tooling problem. It's the kind of functionality that I'll use once, to get a schema started but after that I'll be maintaining the schema myself. From reading a single XML file the XSD generator will create a starting point for a real schema, it cannot infer all the functionality and options offered by XSD. Basically, I don't see the need to have this conversion run as a module inside of my code, generating new XSDs every time the XML changes. After all, it's the schema that defines the XML not the other way around.

As end-user pointed out you could use xsd.exe but you might also want to look at other tools such as trang (a bit old) for Java and stylusstudio (XML tool).

like image 23
jkysam Avatar answered Oct 11 '22 03:10

jkysam