Docstoc

XML

Document Sample
XML Powered By Docstoc
					      XML: Extensible Markup
            Language
• Provides a mechanism to specify tags
   – Not a predefined set of tags
   – XML is a framework for defining markup languages
      (http://www.brics.dk/~amoeller/XML/xml/whatisxml.html)
• Does not define how these tags are interpreted
   – E.g., does not define how they are displayed on
     computer screen
• Tags and other elements defined
   – Using a schema language
             Applications
• XHTML
• Linux “dia” program for drawing diagrams
        Linux “dia” program
• A vector graphics drawing program
• Output format is XML
  – Zipped using gzip, so you have to gunzip to
    view as XML
• Excellent example of commands present in
  vector graphics drawing program
    Part of XML file generated by
         “dia” for a rectangle
<object type="Standard - Box" version="0" id="O0">
  <attribute name="obj_pos">
    <point val="3.55,3.3"/>
  </attribute>
  <attribute name="obj_bb">
    <rectangle val="3.5,3.25;17.25,12.9"/>
  </attribute>
  <attribute name="elem_corner">
    <point val="3.55,3.3"/>
  </attribute>
  <attribute name="elem_width">
    <real val="13.65"/>
  </attribute>
  <attribute name="elem_height">
    <real val="9.55"/>
  </attribute>
  <attribute name="show_background">
    <boolean val="true"/>
  </attribute>
 </object>
                    XHTML
• Extensible HyperText Markup Language
• http://www.w3.org/TR/xhtml1/
• XHTML 1.0
  – a reformulation of HTML 4 as an XML 1.0
• Why?
  – introduce new elements (tags) or additional element
    attributes
  – user agent interoperability in mind
      XML Schema Languages
• Several possible options for defining XML
  tags and elements
  – http://www.brics.dk/~amoeller/XML/schemas/choices.html
  – Using Document Type Definition (DTD)
      • Does not use XML syntax itself
      • Limited support for modularity, reuse
      • Not recommended
          – http://www.brics.dk/~amoeller/XML/schemas/dtd-problems.html

  – XML Schema
      Example – Writing a memo
Modified from http://www.personal.u-net.com/~sgml/xmlintro.htm

<memo>
   <to>All staff</to>
   <from>Martin Bryan</from>
   <date>5th November</date>
   <subject>Cats and Dogs</subject>
   <text>Please remember to keep all cats and dogs indoors
   tonight.</text>
</memo>
   Schema Definition in DTD
<!DOCTYPE memo [ <!ELEMENT memo
  (to, from, date, subject?, text+) >
  <!ELEMENT text (#PCDATA) >
  <!ELEMENT to (#PCDATA) >
  <!ELEMENT from (#PCDATA) >
  <!ELEMENT date (#PCDATA) >
  <!ELEMENT subject (#PCDATA) >
]>
                 Notation:

? indicates that subject tag is optional
+ indicates one or text tags
(#PCDATA) parsed character data i.e. data
   that has been checked to ensure that it
   contains no unrecognized markup strings
   a “leaf node” in the document structure tree
            XML Schema example
• XML Schema
   –   Recent: W3C Recommendation, 2 May 2001
   –   Provides an apparently more useful schema language
   –   Defined in DTD
   –   Documentation:
         • http://www.w3.org/TR/xmlschema-0/
   – http://www.w3.org/2001/XMLSchema.dtd
• Partial Example: Business Cards
   –   http://www.brics.dk/~amoeller/XML/schemas/xmlschema-example.html

• Full Example: Purchase Order
   – Example purchase order instance
         • http://www.w3.org/TR/xmlschema-0/#po.xml
   – XML Schema definition
         • http://www.w3.org/TR/xmlschema-0/#po.xsd
     Part of the Purchase Order
         Schema Definition
<xsd:complexType name="USAddress" >
    <xsd:sequence>
        <xsd:element name="name"
        type="xsd:string"/>
        <xsd:element name="street" type="xsd:string"/>
               <xsd:element name="city"
     type="xsd:string"/>
        <xsd:element name="state" type="xsd:string"/>
        <xsd:element name="zip" type="xsd:decimal"/>
     </xsd:sequence>
   <xsd:attribute name="country"
     type="xsd:NMTOKEN" fixed="US"/>
  Enables Specification of US
Addresses Within Purchase Order
           Instances
<shipTo country="US">
   <name>Alice Smith</name>
   <street>123 Maple Street</street>
   <city>Mill Valley</city>
   <state>CA</state>
   <zip>90952</zip>
</shipTo>
                Some Details
• An XML document must be well-
  formed:
   – E.g., start and end tags must match
• Note: XML is case sensitive!

• http://www.brics.dk/~amoeller/XML/xml/concrete.html
                           Tools
• Schema language tools & information
  – http://www.w3.org/XML/Schema
  – XSV
      • Web based schema language validator
      • http://www.w3.org/2001/03/webdata/xsv
• Other XML tools
  – http://www.brics.dk/~amoeller/XML/xml/tools.html
  – XML parser for Java
      • http://www.alphaworks.ibm.com/tech/xml4j

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:23
posted:8/21/2011
language:English
pages:14