[xsde-users] xs:any and xs:anyAttribute

Eric Broadbent Eric.Broadbent at csr.com
Fri Dec 23 02:11:21 EST 2011


I am not using wildcard or relying on the _any_element handlers, so I don't have the answers you need.

What I have discovered - for content not matching the "any" wildcard, is that elements are ignored unless there is a parser for them, and all of their children will be ignored too.

At least in the non-"any" scenario, if you provide a "root" parser for "detail" without also providing a parser for "event", then your detail parser will not get invoked.  As may be seen below, this may not be the case when "xsd:any" is involved, so I can't answer the question definitively.

The code that controls this is in xsde::cxx::parser::expat::document_pimpl::start_element - which is the main expat element callback:
(a snippet of start_element)
- - - - - - - - - - - - - - - - - - - - - - - - - - -
            ...
            // Dispatch.
            //
            if (cur.depth_ > 0)
            {
              if (cur.any_)
              {
                // Handling content matched by a wildcard.
                //
                cur.depth_++;

#ifdef XSDE_POLYMORPHIC
                cur.parser_->_start_any_element (ns, name, type);
#else
                cur.parser_->_start_any_element (ns, name);
#endif
              }
              else
              {
                // Ignoring content for which there is no parser.
                //
                cur.depth_++;
              }
            }
            else if (cur.parser_)
            {
              // The "normal" case: call _start_element which will
              // call pre() and set the nested parser. We then call
              // _pre_impl on that (which will push the new parser).
              //
              ...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Note that "cur.any_" controls whether elements are ignored - when "cur.depth" is greater than zero.
The "cur.depth" counter will be zero at the top level, and gets incremented when an element is skipped.
I've watched this happen because in my case I want to parse only some of the top-level element's children and ignore others - so I set things up with my root elements as the child elements of interest - but the parsers for them are never getting called.

The situation for the "any" case is different - as you can see from the code.  If the element matches "xsd:any" It looks like your parser may still get called via _start_any_element - even if you don't provide top-level parsers.
As to how you wire up your root elements from there - I haven't had time to look further but perhaps the wildcard example illustrates this.

BTW - if you change the CFLAGS and CXXFLAGS in the top-level config.make so that they don't contain optimization and also include the "-g" option, you can compile the library with symbols - and then you can step through routines like xsde::cxx::parser::expat::document_pimpl::start_element(...), and _start_any_element(...).

Boris will of course have much more valuable things to say, so I apologize if *any* of this is misleading (no pun intended).

-Eric B.
Zoran/CSR


On Dec 23, 2011, at 12:36 AM, Jonathan Haws wrote:

> Boris and Eric,
> 
> I guess my biggest question lies in how to get the sub-schema parsers tied into the main parser.  The wildcard example is not clear to me on how that is done.  
> 
> I have generated code in the following manner:
> 
> This command is for the sub-schemas:
> # xsde cxx-hybrid --generate-parser --generate-serializer --custom-parser --custom-serializer CoT_contact.xsd CoT__flow-tags.xsd CoT_image.xsd CoT_link.xsd CoT_remarks.xsd CoT_request.xsd CoT_sensor.xsd CoT_shape.xsd CoT_spatial.xsd CoT_track.xsd CoT_uid.xsd
> 
> This command is for the top-level schema:
> # xsde cxx-hybrid --generate-parser --generate-serializer --generate-aggregate --custom-data contact --custom-data link --custom-data image --custom-data _flow-tags --custom-data remarks --custom-data request --custom-data sensor --custom-data shape --custom-data spatial --custom-data track --custom-data uid --root-element detail Event-PUBLIC.xsd
> 
> Again, a valid XML has this structure:
> 
> <event>
>  <point/>
>  <detail>
>    <!-- Varied schema(s) found in separate file is added here -->
>  </detail>
> </event>
> 
> I don't know if specifying detail as the root-element is correct?  The generated detail parser skeleton contains routines such as _start_any_element and _end_any_element, but I could not find any references to how I tie in all the lower level parsers.
> 
> Is this a correct statement:  when the top-level parser gets to the <detail> element, it recognizes that what is in <detail> are xs:any fields.  At this point it hands parsing off to the _start_any_element routine.  When a valid XML tag is found, it pulls the name of that tag and calls the appropriate parser for that tag, then moves onto the next one.  Is that correct?  Will XSD/e generate the function table for that if I provide it the correct options?
> 
> Again, what I am looking for is a way to setup a makefile that will generate and tie together all the parsing and serialization code.  Then all I need to do is write the driver.
> 
> Thanks!
> 
> Jonathan
> 
> 
> -----Original Message-----
> From: xsde-users-bounces at codesynthesis.com [mailto:xsde-users-bounces at codesynthesis.com] On Behalf Of Jonathan Haws
> Sent: Thursday, December 22, 2011 22:26
> To: Boris Kolpackov
> Cc: xsde-users at codesynthesis.com
> Subject: RE: [xsde-users] xs:any and xs:anyAttribute
> 
> Here is a quick question:
> 
> In the wildcard examples, how does the driver know that the xs:any is an envelope?  It seems that it is fine with how it is setup now, with envelope being the only option.  But let's say that we have two different envelopes - a square and a rectangle.  How does the driver distinguish that when making the call to _post()?
> 
> In my situation, I have a number of possibilities.  And the stuff in <detail> can be any number of things - a <color>, a <shape>, or something else.  Is there an example of that?  Or am I missing something?
> 
> Thanks!
> 
> Jonathan
> 
> 
> 
> -----Original Message-----
> From: Boris Kolpackov [mailto:boris at codesynthesis.com]
> Sent: Thursday, December 22, 2011 05:20
> To: Jonathan Haws
> Cc: xsde-users at codesynthesis.com
> Subject: Re: [xsde-users] xs:any and xs:anyAttribute
> 
> Hi Jonathan,
> 
> Jonathan Haws <Jonathan.Haws at sdl.usu.edu> writes:
> 
>> Anyway, is there an example that would show how this can be done?
> 
> Yes, see the 'wildcard' example. As Eric mentioned in his reply, you will need to compile each schema separately. Then you will need to route the widlcard content callbacks to the corresponding parser or serializer. The 'wildcard' example shows how to do this.
> 
> Boris
> 
> 
> 
> 
> To report this email as spam click https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg== .



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



More information about the xsde-users mailing list