[xsd-users] CoT schema and xsd followup

Boris Kolpackov boris at codesynthesis.com
Thu Jun 29 05:22:07 EDT 2006


Matt Burnham <mwburn at mhpcc.hpc.mil> writes:

>    Boris,
>
>    Since I don't own the schema's, I'm trying to use the "keep_dom" option.
>    The problem is I can't get the initial DOMElement from my detail using
>    d._node() since my detail object is a container.  I admit, I don't really
>    understand the "containers" so I'm probably missing something.

Since your 'detail' element is optional (minOccurs="0") it may not be
present. So when you call the detail() accessor, you get a container
which you can query for presence and also get the value if it is
present. This is described in detail here:

http://codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.8.2


>    I'm attaching more complete versions of the core schema (event) and the
>    sub-schema (embedded), along with an example xml file.

Thanks, that was helpful.


>    And here is my code:
>
>        std::string fname = "test_event.xml"
>        std::auto_ptr<class event> obj(
>    event(fname,xml_schema::flags::dont_validate|xml_schema::flags::keep_dom)
>    );
>        if( obj->type() == "embedded" )
>        {

If you are sure the detail is present (for example because the type
attribute says so), then you can change it to this:


>            event::detail::container dtl = obj->detail();

to

detail& dtl = obj->detail ().get ();


>            // get the "embedded" data
>            xercesc::DOMElement* de(
>    static_cast<xercesc::DOMElement*>(dtl._node()) );
>            xercesc::DOMNodeList* nl(
>    de->getElementsByTagName("embedded_data") );
>            xercesc::DOMElement* ede( nl->item(0) );
>            embedded_data e_data( ede );
>            // access the "embedded" data
>           e_data.attr1();
>           e_data.attr2();
>        }

The rest looks good.

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/20060629/8b68e9c7/attachment.pgp


More information about the xsd-users mailing list