[xsd-users] Arbitrary XML inside XML element

Attila atteeela at gmail.com
Thu Aug 7 11:54:08 EDT 2008


Hi Boris,

It looks promising, but I am still not quite sure how I would fetch the text
from underneath an element where processContents="skip".

>From the examples/cxx/parser/wildcard/email.xsd:
(I changed processContents to "skip")

....

  <xsd:complexType name="envelope">
    <xsd:sequence>
      <xsd:element name="to" type="xsd:string"/>
      <xsd:element name="from" type="xsd:string"/>
      <xsd:element name="subject" type="xsd:string"/>

      <!-- Extensible envelope body. -->

*      <xsd:any namespace="##targetNamespace" processContents="skip"
               maxOccurs="unbounded" />*
    </xsd:sequence>
    <xsd:anyAttribute namespace="##targetNamespace"
processContents="strict"/>
  </xsd:complexType>

  <xsd:element name="message" type="eml:envelope"/>


Now I would want a way to retrieve all "skipped" content underneath the
<message> element as a string. I do not want callbacks on each any'ed
element (as I have indicated I want to skip processing the contents).

XML Instance:

<message>
   <to>a</to>
   <from>b</from>
   <subject>c</subject>
   <myElement>
      <asdf>...</asdf>
   </myElement>
</message

Would there be a way for me to retrieve:

   <myElement>
      <asdf>...</asdf>
   </myElement>

As text when processing <message>?  I do not quite see how this processing
would fit into the generated skeleton for envelope.  Would I use:

 virtual void
  _any_characters (const ro_string& s)
  {
   // do something
  }

And build up a buffer of any'ed elements that were skipped in here?

Thanks,






On Thu, Aug 7, 2008 at 10:17 AM, Boris Kolpackov <boris at codesynthesis.com>wrote:

> Hi Attila,
>
> Attila <atteeela at gmail.com> writes:
>
> > Thanks for the information.  One more thing: Can I use the C++/Parser to
> do
> > the same thing?
>
> Yes, there is a similar facility in C++/Parser except there you receive
> raw SAX callbacks (e.g., start_element(), end_element(), attribute(),
> and characters()) for content matched by wildcards. The 'wildcard'
> example in examples/cxx/parser/ shows how this works.
>
>
> > I would like to be able to get the sub-XML text for specific nodes, but
> not
> > receive callbacks for the "any'ed" elements that happen to show up.
>  Would
> > there be anyway to perform a test to see if there are "any" elements
> > underneath a specific element that you just received a callback for?
>
> Yes, you can override the above-mentioned functions (see the 'wildcard'
> example for details). There you can ignore/process/save content matched
> by the wildcard in any way you want (including routing it to the another
> parser).
>
> Boris
>



-- 
Attila
Software Developer
atteeela at gmail.com



More information about the xsd-users mailing list