<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Boris,<br>
<br>
Since I don't own the schema's, I'm trying to use the "keep_dom"
option.&nbsp; The problem is I can't get the initial DOMElement from my
detail using d._node() since my detail object is a container.&nbsp; I admit,
I don't really understand the "containers" so I'm probably missing
something.<br>
<br>
I'm attaching more complete versions of the core schema (event) and the
sub-schema (embedded), along with an example xml file.<br>
<br>
And here is my code:<br>
<br>
&nbsp;&nbsp;&nbsp; std::string fname = "test_event.xml"<br>
&nbsp;&nbsp;&nbsp; std::auto_ptr&lt;class event&gt; obj(
event(fname,xml_schema::flags::dont_validate|xml_schema::flags::keep_dom)
);<br>
&nbsp;&nbsp;&nbsp; if( obj-&gt;type() == "embedded" )<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; event::detail::container dtl = obj-&gt;detail();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // get the "embedded" data<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xercesc::DOMElement* de(
static_cast&lt;xercesc::DOMElement*&gt;(dtl._node()) );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xercesc::DOMNodeList* nl(
de-&gt;getElementsByTagName("embedded_data") );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xercesc::DOMElement* ede( nl-&gt;item(0) );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; embedded_data e_data( ede );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // access the "embedded" data<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; e_data.attr1();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; e_data.attr2();<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
Thanks,<br>
Matt<br>
<br>
Boris Kolpackov wrote:
<blockquote cite="mid20060628155330.GA19911@karelia" type="cite">
  <pre wrap="">Hi Matt,

Matt Burnham <a class="moz-txt-link-rfc2396E" href="mailto:mwburn@mhpcc.hpc.mil">&lt;mwburn@mhpcc.hpc.mil&gt;</a> writes:

  </pre>
  <blockquote type="cite">
    <pre wrap="">I've updated my version of xsd to the latest and using some of the added
options, things are now working.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
I am glad it is working for you.


  </pre>
  <blockquote type="cite">
    <pre wrap="">I have a "core" schema that has a placeholder element called "detail".
I then have multiple sub-schemas for data that can go inside of the
"detail" section.  My actual xml file that I'm parsing get's loaded into
the cxx-tree, but I can only access the "detail" element.  Is there any
way to get to the "embedded data?  And then pass this data to the
parsers I have for it?

[...]

&lt;?xml version="1.0" encoding="us-ascii" standalone="yes"?&gt;
&lt;event&gt;
   &lt;detail&gt;
       &lt;embedded-data&gt;
       &lt;/embedded-data/&gt;
   &lt;/detail&gt;
&lt;/event&gt;
    </pre>
  </blockquote>
  <pre wrap=""><!---->
You can do this but it will require a bit of work. The basic idea is
as follows:

(1) Parse your top-level XML with the keep_dom option (see the mixed
    example in examples/cxx/tree).

(2) Obtain DOMElement corresponding to embedded-data node:

    using namespace xercesc;

    detail&amp; d = ...

    DOMElement* de (static_cast&lt;DOMElement*&gt; (d._node ()));
    DOMNodeList* nl (de-&gt;getElementsByTagName ("embedded-data");
    DOMElement* ede (nl-&gt;item (0));

(3) Construct the type corresponding to 'embedded-data' using
    DOMElement:

    embedded_data ed (ede);


There is, however, a better, more elegant way of doing this if you
can change your schemas. The idea is to use XML Schema polymorphism
to define open-ended content. Your 'detail' element can be defined
as follows:

&lt;xs:element name="content" type="xs:anyType"/&gt;

&lt;xs:element name="detail"&gt;
  &lt;xs:complexType&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element ref="content" minOccurs="0" maxOccurs="unbounded"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
&lt;/xs:element&gt;

anyType is an XML Schema built-in type that matches any content.

Now you can use XML Schema substitution groups to define concrete
instances of 'content':

&lt;xs:complexType name="embedded_data"&gt;
  &lt;xs:complexContent&gt;
    &lt;xs:restriction base="xs:anyType"&gt;

      ...

    &lt;/xs:restriction&gt;
  &lt;/xs:complexContent&gt;
&lt;/xs:complexType&gt;

&lt;xs:element name="embedded-data" type="embedded_data" substitutionGroup="content"/&gt;


Your instance still looks exactly the same. But the generated code
handles instantiation of 'embedded_data' automatically:

detail&amp; d = ...

xml_schema::type&amp; c (d.content ()); // xs:anyType maps to xml_schema::type

if (embedded_data* ed = dynamic_cast&lt;embedded_data*&gt; (&amp;c))
{
  // content is embedded_data
}

Individual schemas that define various extension data (like
'embedded_data') can be developed separately from the root
schema which defines the 'content' element (they will need
to include the root schema and be linked into the application,
though). There is an example called polymorphism in
examples/cxx/tree that shows how this works.


hth,
-boris

  </pre>
</blockquote>
</body>
</html>