Question

I'm usign the xsd 3.3.0 Compiler in order to parse a xsd (xml best friend) file to C++ class. (see last weblink)

The comand name is

xsd cxx-tree (options) file.xsd

(+ info http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/)

I've seen some examples provided by codesynthesis where they parse a hello.xsd document and creates a .hxx and a .cxx file very easily. The .hxx has a method to open a xml document creating an object where you can find the diferent parts of the xml, check it, etc... The .hxx has a code like this:

// Parse a URI or a local file.
//

::std::auto_ptr< ::hello_t >
hello (const ::std::string& uri,
       ::xml_schema::flags f = 0,
       const ::xml_schema::properties& p = ::xml_schema::properties ());

It receive a string with the file name

string& uri = "hello.xsd"

and create the object that you use in the main.cxx.

So, I'm trying to do the same with my xsd file. I use the xsd cxx-tree compiler but it doesn't create the methods to "Parse a URI or a local file.". Then I can't create an object from a xml file on my main program.

I solve some compiling problems using differents options from codesys compiler documentation (http://www.codesynthesis.com/projects/xsd/documentation/xsd.xhtml). There are differents options about what do you want to compile, how do you want to do it, etc... but I can't find any options to enable the methods used to "Parse a URI or a local file.".

Giving more onformation, the xml-xsd documents are CBML protocol documents.

Thank you for your help!

Was it helpful?

Solution 2

I found the solution by myself!

I used different options for compiling. I used the option "--root-element library" and it caused that the methods to "Parse a URI or a local file." wasn't created.

I delete this option and I added "--root-element-all" that create parse methods for all principals objects!

Now my program works! thanks!

OTHER TIPS

I use this product all the time.

Here is an example of what you're trying to do (I think):

xsd cxx-tree hello.xsd

Which generates the hello.hxx and the hello.cxx, as you've said. I think where you're falling short is understanding how to use these files to load an XML file (e.g., loading a "local file").

I like to explicitly tell the software where to find the XSD schema. The following code will not compile but I've included it for reference.

void load(const std::string &xml, const std::string &xsd) {
    xml_schema::properties properties;
    properties.no_namespace_schema_location(xsd);
    // or, if you have a specific namespace you want to load, use
    // props.schema_location("which namespace", xsd);
    try {
        std::auto_ptr< ::hello_t> xml_file = hello(xml, 0, props);
        // operate on the xml_file via "->" notation
        std::cout << xml_file->hello() << std::endl;

    } catch (const ::xml_schema::exception &e) {
        std::ostringstream os;
        os << e.what();
        // report the error as you see fit, use os.str() to get the string
    }

}

Make sure to link the *.cxx file to your *.cpp files.

If this is not what you wanted, let me know in the comments and I can try to help you some more.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top