9

Is there any easy way to create at least a template XML file using XML Schema? My main interest is bounded by C++, but discussions of other programming languages are also welcome.By the way I also use QT framework.

metdos
  • 13,411
  • 17
  • 77
  • 120
  • 1
    http://stackoverflow.com/questions/307616/xml-instance-generation-from-xml-schema-xsd –  May 26 '10 at 11:48
  • Check this one... https://stackoverflow.com/questions/17106/how-to-generate-sample-xml-documents-from-their-dtd-or-xsd.. It has accepted answer too and lot other suggestions.. – liaK Jun 01 '10 at 08:14

2 Answers2

4

You may have to write this yourself. There is no one way of getting an XML file from a Schema. If you can make domain-specific assumptions (e.g. how to populate data items, which items to choose in case of a choice, how often to insert domain-specific elements) then you will get a better instance document.

If you are working with C++, note that Xerces C++ allows you to load a schema and access its model (i.e. access it properly, not just load the schema as an XML document). I suggest you download it an check out the SCMPrint Sample. It will show you how to traverse a schema. You can then modify that to print out a sample XML file instead.

xcut
  • 6,219
  • 1
  • 33
  • 27
-1

In Qt 4.5 the XML support has been extended by an XSLT implementation, that allows you to easily convert documents from one XML dialect into another or generating source code from a XML description

W3C XML Schema validation with Qt

Example:

    #include <QtXmlPatterns/QXmlSchema>
    #include <QtXmlPatterns/QXmlSchemaValidator>

    QXmlSchema schema;
    schema.load( QUrl("file:///home/jordenysp/example.xsd") );

    if ( schema.isValid() ) {
        QXmlSchemaValidator validator( schema );
        if ( validator.validate( QUrl("file:///home/jordenysp/result.xml") ) ) {
            qDebug() < < "Is valid";
        } else {
            qDebug() << "Is invalid";
        }
    } else {
        qDebug() << "Is invalid";
    }
jordenysp
  • 2,644
  • 22
  • 17