XML Writing and Parsing: SOA - Lab2
XML Writing and Parsing: SOA - Lab2
XML Writing and Parsing: SOA - Lab2
Parsing
SOA – lab2
The Difference Between XML and HTML
XML Usage
Importance of XML
Agenda
XML main components
XML parsing
XML is not a replacement for HTML.
The XML was designed to describe data, with focus on what data is
Difference HTML was designed to display data, with focus on how data
Between XML looks
Components
also called XML-nodes or XML-tags. The names of
XML-elements are enclosed in triangular brackets
< > as shown below:
• <element>
• Root Element:
<root>
<x>...</x>
<y>...</y>
</root>
• XML Attributes
• An attribute specifies a single
property for the element, using a
XML Main name/value pair. An XML-element
can have one or more attributes.
Cont’d
href="http://www.tutorialspoint.
com/">Tutorialspoint!</a>
• Here href is the attribute name
and
http://www.tutorialspoint.co
m/ is attribute value.
• Sometimes ID references are assigned to elements. These IDs
can be used to identify XML elements in much the same way as
the id attribute in HTML.
XML • <messages>
Metadata <from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
• The id attributes above are for identifying the different notes. It
is not a part of the note itself.
• Metadata (data about data) should be stored as attributes, and
the data itself should be stored as elements.
How to write an XML file?
• The first line in an XML document is called the prolog, it contains XML version, encoding
<?xml version="1.0” encoding="UTF-8" ?>
• Define the root element of your file
• The root element is the first tag you will define in the XML file which will
contain all other elements
• Define the child elements that you will have, the content of each, and
attributes if any
• For Example:
• <contact-info>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
• </contact-info>
XML
Example
XML Example Cont’d
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<!-- This is a comment -->
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
Parse XML in Java