Friday, October 24, 2014

XML

XML rules

  • An XML document must be contained in a single element. - Named Root Element
    • only comments can be out side the root element.
  • XML elements cant overlap
  • End tags are mandatory
  • Elements are case sensitive
  • XML attributes must have values given within quotes(single or double)
    • <ol compact="yes">
  • <!-- comments -->
  • Processing instructions ? 
  • Namespaces: to differentiate element tags which have the same name.
    • Define namespace prefix: xmlns:addr="http://www.xyz.com/addresses/"
    • Use prefix with xml elements: <books:title>
    • Namespace definition must be a unique string

Defining Document Content

Document Type Definition: DTD

Syntax:
  • An Element with comma separated values means the tags must appear and they should be in that order.
  • Optional elements: "?" at the end of their name
  • One or more elements: "+"
  • Zero or more elements: "*"
  • Choices separated with: "|"
  • Attributes are defined giving the accepted values and whether it is optional or required
    • <!ATTLIST city state CDATA #REQUIRED>
XML Schema

Elements:
<xsd:element name="address">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element ref="name"/>
      <xsd:element ref="street"/>
      <xsd:element ref="city"/>
      <xsd:element ref="state"/>
      <xsd:element ref="postal-code"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

Elements:
<xsd:element name="postal-code">
    <xsd:simpleType>
      <xsd:restriction base="xsd:string">
        <xsd:pattern value="[0-9]{5}(-[0-9]{4})?"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:element>



Reference: http://www.ibm.com/developerworks/xml/tutorials/xmlintro/xmlintro.html

No comments:

Post a Comment