Boris Kolpackov-2 wrote:
>
> 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
>
>
Thanks Boris! I just tried that out and it works just like you said.
However, is there any way to do it the way I described?
Is there some way to get the "WidgetType" definition from the schema and
iterate through it to find the default value for an element that is allowed
to be absent from a sequence?
Regards,
Ashish.
--
View this message in context:
http://old.nabble.com/Get-default-value-for-element-from-schema-using-xerces-%28C%2B%2B%29-tp29169204p29187914.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.