[xsd-users] reading and writing non root elements

Boris Kolpackov boris at codesynthesis.com
Thu Nov 30 09:22:49 EST 2006


Hi Greg,

Replying in case somebody else will need this.


Greg Carter <greg at permedia.ca> writes:

> One last problem.  I changed my schema so that the element was global
> and added a ref to it.  I used the code that you gave in the last post
> plus the helper functions in the FAQ.  I also added a call to
> setAttributeNS and added an entry for the prefix for my namespace (tns
> in the example).  In the generated XML I am not getting my root element
> tagged with the prefix, if I manually add the prefix to the root element
> it validates.

I think you forgot to add the namespace and prefix for the root element
in your call to create(). I.e., you have:

create ("elOne");

while you need:

create ("elOne",
        "http://www.blah.com/MySchema",
        "tns");

Also note that you don't need to manually associate the "tns" prefix with
"http://www.blah.com/MySchema" using setAttributeNS since this namespace
will be handled automatically.


> I did step through the XSD generated code to see where the prefix was
> added but it wasn't immediately clear.

It is added automatically by the Xerces-C++ createDocument function.


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/20061130/9682b17c/attachment.pgp


More information about the xsd-users mailing list