Automatic editor of XML (based on XSD scheme) [closed]
Is there any approach to generate editor of an XML file basing on an XSD scheme? (It should be 开发者_运维知识库a Java or Python web based editor).
ExxEditor is an XML editor based on XML Schema. This is a C++ project, and it's not web based at all.
I never used it, but I think the XML Schema files can be annotated to "customize" the UI.
With Jaxe you can automatically create a configuration file from an XSD file, and edit it by hand to improve it. This gives you a specialized XML editor for the language. You can then use this configuration file with WebJaxe to edit your files on the web. It is not suited if you change the XSD all the time, though (you did not specify that)...
Jaxe is a Java application and WebJaxe is using Jaxe as a Java applet for the editor.
Funny, I'm concerning myself with something similar. I'm building an editor (not really WYSIWYG, but it abstracts the DOM away) for the XMLs Civilization 4 (strategy game) usesu to store about everything. I thought about it for quite a while and built two prototypes (in Python), one of which looks promising so I will extend it in the future. Note that Civ 4 XMLs are merely more than a buzzword-conform database (just the kind of data you better store in JSON/YAML and the like, mostly key-value pairs with a few sublists of key-value pairs - no recursive data structures).
My first approach was based on the fact that there are mostly key-value pairs, which doesn't fit documents that exploit the full power of XML (recursive data structures, etc). My new design is more sophisticated - up to now, I only built a (still buggy) validator factory this way, but I'm looking forward to extend it, e.g. for schema-sensetive editing widgets. The basic idea is to walk the XSD's DOM, recognize the expected content (a list of other nodes, text of a specific format, etc), build in turn (recursively) validators for these, and then build a higher-order validator that applies all the previously generated validators in the right order. It propably takes some exposure to functional programming to get comfortable with the idea. For the editing part (btw, I use PyQt), I plan to generate a Label-LineEdit pair for tags which contain text and a heading (Label) for tags that contain other elements, possibly indenting the subelements and/or providing folding. Again, recursion is the key to build these.
Qt allows us to attach a validator to an text input widget, so this part is easy once we can generate a validator for e.g. a tag containing an "int". For tags containing other tags, something similar to the above is possible: Generate a validator for each subelement and chain them. The only part that needs to change is how we get the content. Ignoring comments, attributes, processing instructions, etc, this should still be relatively simple - for a "tag: content" pair, generate "content" and feed it to your DOM parser; for elements with subelements, generate a representation of the children and put it between "...". Attributes could be implemented as key-value pairs too, only with an extra flag.
精彩评论