[xsd-users] cxx-parser and optional element or attribute

Vaughan Roberts Vaughan at Roberts.name
Mon Aug 29 01:19:28 EDT 2011


I have been using cxx-parser to parse an xml document which has a number of
optional elements and attributes.  My problem seems to be that if the
optional element is not present I still get the previous value of the
element returned.  I note that cxx-tree has calls such as:
bar.foo().present() to help determine whether an optional element is present
and bar.foo().get() and bar.foo().reset() functions to deal with them,
however I have not been able to find any reference to these types of
functions in cxx-parser.  How do you handle optional elements in cxx-parser?

 

Here is a snippet from my .xsd file.

  <xsd:complexType name="Over">

    <xsd:sequence>

                        <xsd:element name="bowl" type="xsd:int"/>

                        <xsd:element name="ball" type="Ball" minOccurs="1"
maxOccurs="unbounded"/>

    </xsd:sequence>

  </xsd:complexType>

 

  <xsd:complexType name="Ball">

            <xsd:sequence>

                        <xsd:element name="bat" type="xsd:int"/>

                        <xsd:element name="desc" type="ballType"/>

                        <xsd:element name="fielder" type="xsd:string"
minOccurs="0" maxOccurs="1"/>

                        <xsd:element name="assist" type="xsd:string"
minOccurs="0" maxOccurs="1"/>

            </xsd:sequence>

    <xsd:attribute name="retiredhurt" type="xsd:int" use="optional"/>

    <xsd:attribute name="retired" type="xsd:int" use="optional"/>

  </xsd:complexType>

 

It is the optional elements: fielder and assist that I am having trouble
with at the moment.  If they are provided for a Ball, they only relate to
that Ball and should be reset afterwards.  What I seem to be getting at the
moment is that there is nothing until the first time they have a value and
then that value is returned for all subsequent Balls.

 

Best regards,
Vaughan


Mob: 0412 122 362

 



More information about the xsd-users mailing list