Virus721
Virus721

Reputation: 8315

XML / XSD - Adding descriptions

With XSD I can make sure that an XML file is valid, but is there also a way, using XSD, to attach informations to elements and properties so that a software that would open the XML and XSD file would be able to display that description to the user when he clicks on the element being described?

Upvotes: 5

Views: 7364

Answers (1)

kjhughes
kjhughes

Reputation: 111491

You're describing the xsd:documentation element.

Both xsd:documentation and xsd:appinfo can be included within an xsd:annotation element:

  • Use xsd:documentation to provide meta information to a user.
  • Use xsd:appinfo to provide meta information to a application.

The W3C XML Schema Part 0: Primer Second Edition has an introduction to annotations here, where they provide the following example of how to use xsd:documentation:

<xsd:element name="internationalPrice">
  <xsd:annotation>
    <xsd:documentation xml:lang="en">
         element declared with anonymous type
    </xsd:documentation>
  </xsd:annotation>
  <xsd:complexType>
    <xsd:annotation>
      <xsd:documentation xml:lang="en">
           empty anonymous type with 2 attributes
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexContent>
      <xsd:restriction base="xsd:anyType">
        <xsd:attribute name="currency" type="xsd:string"/>
        <xsd:attribute name="value"    type="xsd:decimal"/>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>
</xsd:element>

Upvotes: 9

Related Questions