Hi,
praetorian20 <[email protected]> writes:
> <xsd:element name="Description" type="xsd:normalizedString"
> default="Unknown" maxOccurs="1" minOccurs="0" />
>
> I'm parsing (DOM parser) an XML file that has been validated against this
> schema using Xerces-C++. If the `Description` element is present, I know how
> to read it by iterating through all the child elements of the `DOMElement`
> for a given `Widget` and using `DOMElement::getTextContent()` upon finding
> the `Description` element.
>
> But, if a particular `Widget` element does not have a `Description` child
> element (which is allowed by the schema), how can I fetch the default value
> (`Unknown`) from the schema?
Xerces-C++ XML Schema processor has support for default attribute/element
values in that it will supply the default values as if they were specified
in the XML being parsed.
The problem with your situation is that you are using default elements
incorrectly. In XML Schema an element takes the default value if it is
present but has empty value, not if is is not present (which is how
attributes work). In other words:
<outer>
<Description>foo</Description> <!-- value 'foo' -->
<outer>
<outer>
<Description></Description> <!-- value 'Unknown' (default) -->
<outer>
<outer>
<!-- Description element not present -->
<outer>
Boris
--
Boris Kolpackov, Code Synthesis http://codesynthesis.com/~boris/blog
Open-source XML data binding for C++ http://codesynthesis.com/products/xsd
XML data binding for embedded systems http://codesynthesis.com/products/xsde
Command line interface to C++ compiler http://codesynthesis.com/projects/cli