0% found this document useful (0 votes)
12 views21 pages

Introduction XML

XML is a markup language that stores and transports data. It was designed to be software- and hardware-independent. XML documents must have a single root element, properly nested elements, closed tags, and elements names follow specific naming rules. XML uses tags that are not predefined like HTML, and it preserves whitespace. Attributes must be quoted and XML documents must be well-formed to conform to syntax rules.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views21 pages

Introduction XML

XML is a markup language that stores and transports data. It was designed to be software- and hardware-independent. XML documents must have a single root element, properly nested elements, closed tags, and elements names follow specific naming rules. XML uses tags that are not predefined like HTML, and it preserves whitespace. Attributes must be quoted and XML documents must be well-formed to conform to syntax rules.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

XML

• XML is a software- and hardware-independent


tool
• XML stands for EXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to store and transport data
• XML was designed to be self-descriptive
• XML is a W3C Recommendation
Note.xml

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML AND HTML
• XML and HTML were designed with different
goals:
• XML was designed to carry data - with focus
on what data is
• HTML was designed to display data - with
focus on how data looks
• XML tags are not predefined like HTML tags
are
STRUCTURE OF XML DOCUMENT
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
XML SYNTAX
XML Documents Must Have a Root Element

XML documents must contain one root element that is the parent of all other
elements:
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
The XML Prolog

This line is called the XML prolog:


<?xml version="1.0" encoding="UTF-8"?>

The XML prolog is optional. If it exists, it must come first in the document.
All XML Elements Must Have a Closing Tag

<p>This is a paragraph.</p>
<br />
XML Tags are Case Sensitive
XML tags are case sensitive. The tag <Letter> is different from the tag
<letter>.

Opening and closing tags must be written with the same case:

<Message>This is incorrect</message>
<message>This is correct</message>
XML Elements Must be Properly Nested

<b><i>This text is bold and italic</i></b>


XML Attribute Values Must be Quoted

<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>
Entity References

This will generate an XML error:


<message>salary < 1000</message>

To avoid this error, replace the "<" character with


an entity reference:
<message>salary &lt; 1000</message>

There are 5 pre-defined entity references in XML:

&lt; < less than


&gt; > greater than
&amp; & ampersand
&apos; ' apostrophe
&quot; " quotation
mark
Comments in XML

The syntax for writing comments in XML is


similar to that of HTML.

<!-- This is a comment -->


White-space is Preserved in XML
Well Formed XML
XML documents that conform to the syntax rules above are said to be
"Well Formed" XML documents.
XML Elements

An XML element is everything from (including) the element's start tag to


(including) the element's end tag.

<price>29.99</price>

An element can contain: <bookstore>


text <book category="children">
attributes <title>Harry Potter</title>
other elements <author>J K. Rowling</author>
or a mix of the above <year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
In XML, you can indicate an empty element like this:

<element></element>

You can also use a so called self-closing tag:

<element />

Empty elements can have attributes.


XML Naming Rules

XML elements must follow these naming rules:


•Element names are case-sensitive
•Element names must start with a letter or underscore
•Element names cannot start with the letters xml (or XML, or Xml,
etc)
•Element names can contain letters, digits, hyphens, underscores,
and periods
•Element names cannot contain spaces
•Any name can be used, no words are reserved (except xml).
XML Attributes

XML Attributes Must be Quoted

<person gender="female">

or like this:

<person gender='female'>

If the attribute value itself contains double quotes you can use single
quotes, like in this example:

<gangster name='George "Shotgun" Ziegler'>

or you can use character entities:

<gangster name="George &quot;Shotgun&quot; Ziegler">

You might also like