[SOLVED]Validate an XML document
I am developing a Petri Net Editor. A Petri net is a set of Places(ellipce items), transitons (rect items), Arc (path items) and Labels (text items) drawn in a graphicsScene.
I want to add the file save functionality to the application and XML is the best way. "PNML core model":http://www.pnml.org/version-2009/grammar/pnmlcoremodel.rng is the standard specification.
What is the better way : using QDomDocument or QXmlStreamWriter/Reader ?
How can i validate the xml document before open it ?
I mean is there a Qt tool to validate such doc ori have to implement the validator ?
thanks in advance.
Qt does AFAIK not support validation of Relax NG schema definitions, so if you want to validate input against that schema you should find some 3rd-party component that offers validation. Implementing the validation yourself is most likely not trivial and not worth the effort. If you can get a hold of a W3C XML Schema for the desired format you can use QXmlSchemaValidator contained in the QtXmlPatterns module for validation.
You could try to use QXmlSchema/QXmlDTDHandler for validation.
I would prefer QXmlStreamWriter/Reader as it seems to be faster and less memory consuming than QDomDocument. From the other side if you need to have whole xml document structure loaded then QDomDocument could be good container for you. Unfortunately the answer strongly depends on your internal requirements, so probably nobody can give you clear clue which class would be best for you.
OOps, i didn't see the QtXmlPatterns module. It is the key !
So i will use :
- QXmlSchema : to validate the data definition schema.
- QXmlSchemaValidator : to validate the xml doc
- QXmlStreamWriter/Reader : to read write the xml doc
Thanks all. :)