190 likes | 308 Vues
Introduction to XML BKF04. Brian Ciccolo. Agenda. XML revealed What is it and why should I care? Syntax semantics Elements and tags and attributes, oh my! Document validation Following the rules of the road. XML Revealed. What is it? eXtensible Markup Language Structured data.
E N D
Introduction to XMLBKF04 Brian Ciccolo
Agenda • XML revealed • What is it and why should I care? • Syntax semantics • Elements and tags and attributes, oh my! • Document validation • Following the rules of the road
XML Revealed • What is it? • eXtensible Markup Language • Structured data Why should I care? • It’s used throughout Aspen • It’s easy to learn • It’s fun!
Music Collection Example • A simple hierarchy: • Artists • Albums • Songs • Beatles • The White Album • Back in the U.S.S.R. • Helter Skelter • Abbey Road • Come Together • Oh! Darling
Tags: The Building Blocks of XML <music-collection> This is my music collection. Not very impressive yet. </music-collection>
XML Syntax Rule 1 • Every opened tag must be closed. Good Bad <example1> stuff </example1> <example2 /> <example3> more stuff
Nested Tags <music-collection> <artist>Beatles</artist> <artist>Frank Sinatra</artist> <artist>U2</artist> </music-collection>
XML Syntax Rule 2 • All children tags must be closed • before the parent tag is closed. Good Bad <parent> <child>hi!</child> </parent> <parent> <child>hi! </parent> </child>
Tag Attributes <album title=“Abbey Road”year=“1969”> <song>Come Together</song> <song>Oh! Darling</song> </album>
XML Syntax Rule 3 • Attributes must be located in the open tag, • and their values must be wrapped in quotation marks. Good Bad <pet name=“Lucky” /> <pet name=“Spot”> <type>Dog</type> </pet> <state name=MA /> <state> <city>NYC</city> </state name=“NY”>
Other Syntax Tidbits • <?xml version="1.0"?> • <!-- comments --> • Special characters
Validating with DTD • Document Type Definition • Defines the elements and attributes allowed within an XML document • Syntax based on the XML we just learned
Element Definition <!ELEMENT artist (comment?, member*, album+)> <!ELEMENT comment #PCDATA> <!ELEMENT member EMPTY> <!ELEMENT album (song+)> <!ELEMENT song EMPTY>
DTD Example 1 Good Bad <artist> <member>...</member> <member>...</member> <album>...</album> <album>...</album> <album>...</album> </artist> <!-- snippet 1 --> <artist> <member>...</member> <comment>...</comment> </artist> <!-- snippet 2 --> <song>...</song>
Attribute Definition <!ATTLIST album name CDATA #REQUIRED year CDATA #REQUIRED format (CD|MP3) "MP3">
DTD Example 2 Good Bad <album name=“The White Album” year=“1968”> ... </album> <album year=“1969” format=“CD” name=“Abbey Road”> ... </album> <album name=“Abbey Road” format=“Vinyl”> ... </album>
Extras • w3schools.com XML Tutorialhttp://www.w3schools.com/xml • W3C XML Specificationhttp://www.w3.org/TR/REC-xml • Notepad++ text editorhttp://notepad-plus.sourceforge.net
Thank you. bciccolo@x2dev.com