[xsd-users] adding xsd:any nodes to node-objects

Boris Kolpackov boris at codesynthesis.com
Tue Apr 11 04:10:08 EDT 2006


Hi Oliver,

Oliver.Kowalke at infineon.com <Oliver.Kowalke at infineon.com> writes:

> The hello.xsd class-library generated by xsd allows access to the
> embedded xml in c-node (for instance embed.xml in the sample).
>
> I can also create a class-library for embed.xsd via xsd-tool.
> Access to the embedded xml would be:
>
> DOMNode * embed = c_n._node()->getFirstChild();
> xyz::embed_type e_n (static_cast<DOMElement*> (embed), 0, 0);
>
> I need to know how can I add a xyz::embed_type instance to a c_n
> instance (other direction than previous example)?

You cannot really add it unless there is a slot in c_type (e.g.,
element or attribute) for it. One way to create such a slot is to
modify your hello.xsd schema:

<?xml version="1.0"?>
<xsd:schema
       targetNamespace="abc"
       xmlns="abc"
       xmlns:xyz="xyz"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       elementFormDefault="qualified">

        <xsd:import namespace="xyz" schemaLocation="embed.xsd"/>

        ...

	<xsd:complexType name="c_type" mixed="true">
		<xsd:sequence>
                        <xsd:any namespace="##other" processContents="skip" minOccurs="0"/>
                        <xsd:element name="embed" type="xyz:embed_type" minOccurs="0"/>
		</xsd:sequence>
	</xsd:complexType>

        ...

</xsd:schema>


You can modify the schema only for code generation and use the original
schema for validation. With c_type generated from the schema above, you
can rewrite you code like this:

DOMNode * embed = c_n._node()->getFirstChild();
xyz::embed_type e_n (static_cast<DOMElement*> (embed), 0, 0);
c_n.embed (e_n);

Also note that you will need to reset the embed element before serialization
if you don't want it to be written out:

c_n.embed ().reset ();


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/20060411/ca4dd9eb/attachment.pgp


More information about the xsd-users mailing list