1 / 12

XML Syntax: Documents

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.

heller
Télécharger la présentation

XML Syntax: Documents

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML Syntax: Documents Andy Clark 17 Apr 2002

  2. Basic Document Structure • Element tags • Elements have associated attributes • Text content • Miscellaneous • Encoding, document type declarations • Entity references • Comments, processing instructions, etc…

  3. Example XML Document (1 of 6) • XML declaration 01 <?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>

  4. Example XML Document (2 of 6) • Document type declaration 01 <?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>

  5. Example XML Document (3 of 6) • Processing instructions 01 <?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>

  6. Example XML Document (4 of 6) • Element tags 01 <?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>

  7. Example XML Document (5 of 6) • Attributes of element tags 01 <?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>

  8. Example XML Document (6 of 6) • Text content 01 <?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>

  9. 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!

  10. 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)

  11. 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/

  12. XML Syntax: Documents Andy Clark

More Related