12

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."

Community
  • 1
  • 1
chobok
  • 423
  • 4
  • 19

3 Answers3

6

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!).

microe14
  • 2,711
  • 1
  • 15
  • 5
  • Just tested, and it has the option, works very well, thanks! – acaruci Oct 25 '19 at 12:58
  • https://www.jetbrains.com/help/pycharm/generating-xml-schema-from-instance-document.html , more information about conversion using Pycharm. – Murali Jun 18 '20 at 11:25
3

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?

end-user
  • 2,845
  • 6
  • 30
  • 56
  • It should be possible to do what I want and access tools like xsd.exe from within a Python program. I would preferred to use something like a Python module as it's easier to work with and more elegant a solution. pyxsd/PyXB don't seem to satisfy my requirements (as far as I can tell they don't have the ability to produce a schema, given an XML document). – chobok Nov 17 '11 at 03:30
1

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).

jkysam
  • 5,533
  • 1
  • 21
  • 16