XML Syntax: Documents

12
17 Apr 2002 XML Syntax: Documents Andy Clark

description

XML Syntax: Documents. Andy Clark. Basic Document Structure. Element tags Elements have associated attributes Text content Miscellaneous Encoding, document type declarations Entity references Comments, processing instructions, etc…. Example XML Document (1 of 6). XML declaration. - PowerPoint PPT Presentation

Transcript of XML Syntax: Documents

Page 1: XML Syntax: Documents

17 Apr 2002

XML Syntax: Documents

Andy Clark

Page 2: XML Syntax: Documents

Basic Document Structure

Element tags– Elements have associated attributes

Text content Miscellaneous

– Encoding, document type declarations– Entity references– Comments, processing instructions, etc…

Page 3: XML Syntax: Documents

Example XML Document (1 of 6)

XML declaration01 <?xml version=‘1.0’ encoding=‘Shift_JIS’?>

02 <!DOCTYPE order SYSTEM ‘grammar.dtd’>

03 <?xml-stylesheet type=‘text/xsl’ href=‘style.xsl’?>

04 <order>

05 <item code=‘BK123’>

06 <name>Care and Feeding of Wombats</name>

07 <price currency=‘USD’>42.00</price>

08 </item>

09 </order>

Page 4: XML Syntax: Documents

Example XML Document (2 of 6)

Document type declaration01 <?xml version=‘1.0’ encoding=‘Shift_JIS’?>

02 <!DOCTYPE order SYSTEM ‘grammar.dtd’>

03 <?xml-stylesheet type=‘text/xsl’ href=‘style.xsl’?>

04 <order>

05 <item code=‘BK123’>

06 <name>Care and Feeding of Wombats</name>

07 <price currency=‘USD’>42.00</price>

08 </item>

09 </order>

Page 5: XML Syntax: Documents

Example XML Document (3 of 6)

Processing instructions01 <?xml version=‘1.0’ encoding=‘Shift_JIS’?>

02 <!DOCTYPE order SYSTEM ‘grammar.dtd’>

03 <?xml-stylesheet type=‘text/xsl’ href=‘style.xsl’?>

04 <order>

05 <item code=‘BK123’>

06 <name>Care and Feeding of Wombats</name>

07 <price currency=‘USD’>42.00</price>

08 </item>

09 </order>

Page 6: XML Syntax: Documents

Example XML Document (4 of 6)

Element tags01 <?xml version=‘1.0’ encoding=‘Shift_JIS’?>

02 <!DOCTYPE order SYSTEM ‘grammar.dtd’>

03 <?xml-stylesheet type=‘text/xsl’ href=‘style.xsl’?>

04 <order>

05 <item code=‘BK123’>

06 <name>Care and Feeding of Wombats</name>

07 <price currency=‘USD’>42.00</price>

08 </item>

09 </order>

Page 7: XML Syntax: Documents

Example XML Document (5 of 6)

Attributes of element tags01 <?xml version=‘1.0’ encoding=‘Shift_JIS’?>

02 <!DOCTYPE order SYSTEM ‘grammar.dtd’>

03 <?xml-stylesheet type=‘text/xsl’ href=‘style.xsl’?>

04 <order>

05 <item code=‘BK123’>

06 <name>Care and Feeding of Wombats</name>

07 <price currency=‘USD’>42.00</price>

08 </item>

09 </order>

Page 8: XML Syntax: Documents

Example XML Document (6 of 6)

Text content01 <?xml version=‘1.0’ encoding=‘Shift_JIS’?>

02 <!DOCTYPE order SYSTEM ‘grammar.dtd’>

03 <?xml-stylesheet type=‘text/xsl’ href=‘style.xsl’?>

04 <order>

05 <item code=‘BK123’>

06 <name>Care and Feeding of Wombats</name>

07 <price currency=‘USD’>42.00</price>

08 </item>

09 </order>

Page 9: XML Syntax: Documents

Differences with HTML

Elements must be balanced, properly nested e.g. <br /> OK e.g. <b>bold <i> and italic </i> text</b> OK e.g. <b>bold <i> and italic </b> text</i> BAD! e.g. <ul> <li> list item </ul> BAD!

Attributes must be specified, quoted e.g. <img src=‘images/banner.gif’/> OK e.g. <img src=images/banner.gif /> BAD! e.g. <ul compact> <li> list item </li> </ul> BAD!

Page 10: XML Syntax: Documents

Other Important Points

Documents must be well-formed– Document contains single root element– Elements are balanced and properly nested– Attributes are specified and quoted– Text content contains legal XML characters

Documents may be valid– Document structure and content follows rules

specified by grammar (e.g. DTD, XML Schema)

Page 11: XML Syntax: Documents

Useful Links

XML 1.0 Specification– http://www.w3.org/TR/REC-xml

Annotated XML 1.0 Specification– http://www.xml.com/axml/testaxml.htm

Informational web sites– http://www.xml.com/– http://www.xmlhack.com/

Page 12: XML Syntax: Documents

XML Syntax: Documents

Andy Clark