introduction to xml bkf04 brian ciccolo. agenda xml revealed what is it and why should i care?...
TRANSCRIPT
![Page 1: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/1.jpg)
Introduction to XMLBKF04
Brian Ciccolo
![Page 2: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/2.jpg)
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
![Page 3: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/3.jpg)
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!
![Page 4: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/4.jpg)
Music Collection Example
A simple hierarchy:•Artists
oAlbumsSongs
•BeatlesoThe White Album
Back in the U.S.S.R.Helter Skelter
oAbbey RoadCome TogetherOh! Darling
![Page 5: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/5.jpg)
Tags: The Building Blocks of XML
<music-collection>
This is my music collection.
Not very impressive yet.
</music-collection>
![Page 6: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/6.jpg)
XML Syntax Rule 1Every opened tag must be closed.
<example1>
stuff
</example1>
<example2 />
<example3>
more stuff
Good Bad
![Page 7: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/7.jpg)
Nested Tags
<music-collection>
<artist>Beatles</artist>
<artist>Frank Sinatra</artist>
<artist>U2</artist>
</music-collection>
![Page 8: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/8.jpg)
XML Syntax Rule 2All children tags must be closedbefore the parent tag is closed.
<parent>
<child>hi!</child>
</parent>
<parent>
<child>hi!
</parent>
</child>
Good Bad
![Page 9: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/9.jpg)
Tag Attributes
<album title=“Abbey Road”
year=“1969”>
<song>Come Together</song>
<song>Oh! Darling</song>
</album>
![Page 10: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/10.jpg)
XML Syntax Rule 3Attributes must be located in the open tag,
and their values must be wrapped in quotation marks.
<pet name=“Lucky” />
<pet name=“Spot”>
<type>Dog</type>
</pet>
<state name=MA />
<state>
<city>NYC</city>
</state name=“NY”>
Good Bad
![Page 11: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/11.jpg)
Other Syntax Tidbits
• <?xml version="1.0"?>
• <!-- comments -->
• Special charactersCharacter Representation Meaning
> > Greater than
< < Less than
“ " Quote
& & Ampersand
![Page 12: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/12.jpg)
Validating with DTD
• Document Type Definition
• Defines the elements and attributes allowed
within an XML document
• Syntax based on the XML we just learned
![Page 13: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/13.jpg)
DTD SymbolsSymbol Definition
() The items within the parentheses define the contents of the element or attribute
? Either 0 or 1 instances of an element is allowed (i.e., the element is optional)
+ 1 or more instances of an element is allowed (i.e., the element is required)
* 0 or more instances of an element is allowed (i.e., the element is not required)
| The items separated by the pipe define the allowed values for an element
EMPTY The element cannot contain body content
CDATA Character data that is not parsed
#PCDATA Character data that is parsed
#REQUIRED The attribute is required, a value must be specified
#IMPLIED The attribute is optional; if a value is not specified, then some default value will be used
![Page 14: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/14.jpg)
Element Definition
<!ELEMENT artist
(comment?, member*, album+)>
<!ELEMENT comment #PCDATA>
<!ELEMENT member EMPTY>
<!ELEMENT album (song+)>
<!ELEMENT song EMPTY>
![Page 15: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/15.jpg)
DTD Example 1
<artist>
<member>...</member>
<member>...</member>
<album>...</album>
<album>...</album>
<album>...</album>
</artist>
<!-- snippet 1 -->
<artist>
<member>...</member>
<comment>...</comment>
</artist>
<!-- snippet 2 -->
<song>...</song>
Good Bad
![Page 16: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/16.jpg)
Attribute Definition
<!ATTLIST album
nameCDATA #REQUIRED
yearCDATA #REQUIRED
format (CD|MP3) "MP3">
![Page 17: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/17.jpg)
DTD Example 2
<album
name=“The White Album”year=“1968”>...
</album>
<album year=“1969”
format=“CD”
name=“Abbey Road”>...
</album>
<album
name=“Abbey Road”format=“Vinyl”>...
</album>
Good Bad
![Page 18: 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!](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649e355503460f94b2436e/html5/thumbnails/18.jpg)
Extras
• w3schools.com XML Tutorial
http://www.w3schools.com/xml
• W3C XML Specification
http://www.w3.org/TR/REC-xml
• Notepad++ text editor
http://notepad-plus.sourceforge.net