4. What is an xml Element?
Elements are the main component of an XML document.
An element is represented by using a start tag (<>
and an end tag (</>
.
For example: Book element can be represented as <Book></Book>
Everything between the start and end tags of an element is considered to be the content of the element.
The content of an element can be
character data - CDATA(text),
no content (empty element), or
other elements (known as child elements).
Elements can also contain comments, processing instructions, or entity references.
We can represent empty elements with a single special tag
Example : <Book/>
This is equivalent to: <Book></Book>
--------------------------------- End ---------------------------------
5. What is an Attribute?
Attributes give you more information about the data an element represents.
An element can contain any number of attributes.
Attributes are specified as name-value pairs and they appear within the start tag of the element.
Attribute values are enclosed within quotes.
An attribute value may contain text characters, entity references, or character references.
Attribute names are unique within the same element. That is in a single element, no two attributes can have the same name.
For example:
<Book isbn="s325-034-778"></Book>
is valid,
but
<Book isbn="s325-034-778" isbn="s353-412-341"></Book>
is not valid.
--------------------------------- End ---------------------------------
6. Well-formed XML Document?
XML code that follows certain rules defined in the W3C XML specifications is called well-formed XML.
An XML document is said to be well formed if:
For each element defined in the XML document, every start tag has a corresponding end tag.
All the XML elements must nest properly within each other.
For example,
<book><name></book></name>
is not allowed, but
<book><name></name></book>
is allowed.
In each element, no two attributes have the same name.
Markup characters are properly specified.
The document contains only one root element.
That is an element that is present only once in the document and does not appear as a child of any other element.
The first element must contain the special tag that identifies the file as an XML document.
Attributes (extra information that can be provided for an elements) must be properly quoted.
Both the elements and attributes must follow the proper naming conventions.
--------------------------------- End ---------------------------------