XML Intro
XML Intro
The tree starts at the root and branches to the lowest level
of the tree.
</root> </note>
XML – Syntax Rule 7
All XML Elements Must Have a Closing Tag.
HTML syntax:
<p>This is a paragraph
<p>This is another paragraph
In XML syntax :
<p>This is a paragraph</p>
<p>This is another paragraph</p>
XML – Syntax Rule 8
XML Tags are Case Sensitive.
<Message>This is incorrect</message>
<message>This is correct</message>
XML – Syntax Rule 9
XML Elements Must be Properly Nested.
In HTML
In XML
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
XML – Syntax Rule 11
XML Attribute Values Must be Quoted.
Correct One :
XML – Elements
XML Elements
other elements
text
attributes
or a mix of all of the above...
16
There are 5 predefined entity references in XML:
XML – Elements
<bookstore>
<book category="CHILDREN">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
</book>
<book category="WEB">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
</book>
</bookstore>
XML – Elements 17
XML Naming Rules
Names cannot start with the letters xml (or XML, or Xml,
etc)
<note>
<note> <to>Tove</to>
<to>Tove</to> <from>Jani</from>
<from>Jani</from> <body>Don't forget me<body>
<body>Don't forget me <body> <mes> Its ok </mes>
</note> </note>
XML – Attributes 21
XML elements can have attributes, just like HTML.
<firstname>Anna</firstname> <gender>female</gender>
<lastname>Smith</lastname> <firstname>Anna</firstname>
</person> <lastname>Smith</lastname>
</person>
XML – Attributes 23
<note date="10/01/2008"> <note>
<to>Tove</to> <date>
<from>Jani</from> <day>10</day>
<heading>Reminder</heading> <month>01</month>
<body>Don't forget me !</body> <year>2008</year>
</note> </date>
<note> <to>Tove</to>
<date>10/01/2008</date> <from>Jani</from>
<to>Tove</to> <heading>Reminder</heading>
<from>Jani</from> <body>Don't forget me </body>
<heading>Reminder</heading> </note>
<body>Don't forget me!</body>
</note>
XML – Validation 24
"Well Formed" XML
"Valid" XML.
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me!</body>
</note>
XML – Validation 27
“Valid “ XML document
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
XML – Viewing 30
Viewing XML Files
BOOK DETAILS
<BOOKDETAILS>
<BOOK ID="TERI101">
<BOOKNAME>C PROGRAMMING</BOOKNAME>
<AUTHOR> DENNIS RITCHE</AUTHOR>
</BOOK>
<BOOK ID="TERI102">
<BOOKNAME>JAVA COMPLETE REFERENCE</BOOKNAME
<AUTHOR> PATTRICK NAUGHTON</AUTHOR>
</BOOK>
<BOOK ID="TERI103">
<BOOKNAME>LET US C</BOOKNAME>
<AUTHOR> YASHWANT KANITKAR</AUTHOR>
</BOOK>
</BOOKDETAILS>
Queries
&
Suggestions
Thanks