You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "Ferguson, Neil D" <Ne...@yuma.army.mil> on 2006/08/31 16:21:34 UTC

Creating a document from a schema

In my application I want to use xerces-c to create a skeleton of a DOM
document  based on a schema containing default values for all elements.
There would be no XML file to parse.  I would then find document nodes by
name and set the element values programmatically to their actual values.
After I have set the values I would then write the document to an XML file
that has the necessary attributes to associate itself with the schema.
 
How do I get the document object without parsing and XML file?  Is this
feasible with xerces-c?  If so, can you point me to where I should start?  I
mean beyond the API TOC - I've studied the API and samples and haven't found
the answer yet ;).

Re: Creating a document from a schema

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Neil,

"Ferguson, Neil D" <Ne...@yuma.army.mil> writes:

> In my application I want to use xerces-c to create a skeleton of a DOM
> document  based on a schema containing default values for all elements.
> There would be no XML file to parse.  I would then find document nodes by
> name and set the element values programmatically to their actual values.
> After I have set the values I would then write the document to an XML file
> that has the necessary attributes to associate itself with the schema.

No, this not supported in Xerces-C++. It is also a not very well defined
problem in the general case. Imagine you have a schema like this:

  <xsd:complexType name="Foo">
    <xsd:sequence>
      <xsd:element name="bar" type="xsd:string" maxOccurs="10" default="bar"/>
    </xsd:sequence>
  </xsd:complexType>

How many bar elements should the default document contain, 0, 1, 10?

For what it's worth, our open-source XML data binding compiler[1] does
what you want but only for elements with cardinality "exactly 1" and
required attributes.


[1] http://www.codesynthesis.com/products/xsd/


hth,
-boris


-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding