开发者

Get default value for element from schema using xerces (C++)

Say I have a schema which defines an element as follows:

<xsd:element name="Widget" type="tns:WidgetType" />

<xsd:complexType name="WidgetType">
  <xsd:sequence>

    <xsd:element name="Name" type="xsd:normalizedString" maxOccurs="1" minOccurs="1" />
    <xsd:element name="Description" type="xsd:normalizedString" default="Unknown" maxOccurs="1" minOccurs="0" />

  </xsd:sequence>
</xsd:complexType>

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 h开发者_如何学Cave a Description child element (which is allowed by the schema), how can I fetch the default value (Unknown) from the schema?

Thanks for your responses, Ashish


You should be able to use XPath or XQuery to query the schema document to grab any values off of the schema document. Xerces site says it has partial XPath support, and lists Xalan and XQilla if you need more power.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜