[xsd-users] Creating an XML without parsing an existing one
Boris Kolpackov
boris at codesynthesis.com
Fri Jan 6 04:41:25 EST 2006
Sherif,
Yacoub, Sherif <yacoub at amazon.com> writes:
> However, I have a question about the creation of an XML from scratch
> i.e. I don't have an XML and I want my program to create it.
>
> Using the library example in the distribution, what will be the
> constructor to use to create an instance of the "catalog" root node
> for example?
Citing Section 2.7, "Mapping for Complex Types" from the manual:
http://codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.7
"Additionally, the resulting C++ class defines a public constructor
that takes an initializer for each member of the complex type and
all its base types that belongs to the One cardinality class."
Looking at the catalog type definition
<xsd:complexType name="catalog">
<xsd:sequence>
<xsd:element name="book" type="lib:book" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
we conclude that the constructor won't have any arguments since the
only member of this type (element book) belongs to the Sequence
cardinality class (maxOccurs="unbounded"). Here is a code snippet
that constructs a simple catalog from scratch:
using namespace library;
class catalog cat;
{
book b (201700735, // ISBN
title ("The C++ Programming Language"), // Title
genre::philosophy, // Genre
"CXXPL"); // ID
b.author ().push_back (author ("Bjarne Stroustrup", "1950-03-31"));
cat.book ().push_back (b);
}
{
book b (20170434, // ISBN
title ("More Exceptional C++"), // Title
genre::fiction, // Genre
"MECXX"); // ID
author a ("Herb Sutter", "1960-03-31");
a.recommends ("CXXPL");
b.author ().push_back (a);
cat.book ().push_back (b);
}
// The cat object now contains two books.
hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20060106/864c60e6/attachment.pgp
More information about the xsd-users
mailing list