Coupon Accepted Successfully!


What is an XML Element?

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


An element can contain other elements, simple text or a mixture of both. Elements can also have attributes.

<book category="CHILDREN">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<book category="WEB">
<title>Learning XML</title>
<author>Erik T. Ray</author>

In the example above, <bookstore> and <book> have element contents, because they contain other elements. <author> has text content because it contains text.

In the example above only <book> has an attribute (category="CHILDREN").

XML Attributes

XML attributes are normally used to describe XML elements, or to provide additional information about elements. From HTML you can remember this construct: <IMG

SRC="computer.gif">. In this HTML example SRC is an attribute to the IMG element.

The SRC attribute provides additional information about the element.

Attributes are always contained within the start tag of an element. Here are some examples:

HTML examples:

<img src="computer.gif">
<a href="demo.asp">
XML examples:
<file type="gif">
<person id="3344">


Usually, or most common, attributes are used to provide information that is not a part of the content of the XML document. Did you understand that? Here is another way to express that: Often attribute data is more important to the XML parser than to the reader.

Did you understand it now? Anyway, in the example above, the person id is a counter value that is irrelevant to the reader, but important to software that wants to manipulate the person element.


XML Validation

The following is a "Well Formed" XML document:

<?xml version="1.0"?>
<body>Don't forget me this weekend!</body>

"Valid" XML documents

A "Valid" XML document is a "Well Formed" XML document which conforms to the rules of a Document Type Definition (DTD).

The following is the same document as above but with an added reference to a DTD:

<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "InternalNote.dtd">
<body>Don't forget me this weekend!</body>

A "Well Formed" XML document is a document that conforms to the XML syntax rules that we described in the previous chapter.

Test Your Skills Now!
Take a Quiz now
Reviewer Name