XML Syntax

Created by
Monday, August 29, 2016

XML refers to Extensible Markup Language. It is used to store and to transport data.

XML SYNTAX DOESN’T HAVE PREDEFINED TAGS

The XML language do not have any predefined tags.

The tags in the example below(student, course, etc) are not defined in any XML standard. These tags are “Created” by the author of the XML document.

HTML works with predefined tags like  <h1>, <p>, <table>, etc.

With XML, the developer must define both the document structure and  the tags. And each tag must have its starting and ending tags.

EXAMPLE:

    <college>
     <course1>
     <subject1></subject1>
     <subject2></subject2>
     </course1>
     <course2>
     <subject3></subject3>
     </course2>
    </college>

The above example explain how we could arrange the element tags to maintain the data through XML.

In the above example, It explain that a college may have multiple courses and each course have their subjects.

This is how we write XML document.
The Elements in XML document may contain other elements or data or nothing. 

EXAMPLE 2:

    <root>
     <child1>
     <subchild>syntax definition</subchild>
     </child1>
     <child2>
     </child2>
    </root>

In the above example first tag also refer as element named as root contains two sub elements named child1 and child2.

And child1 contain a data value which is “syntax definition” where as element named as child2is empty

 

PROLOG

A Prolog defines the XML version and the character encoding. However it is completely optional but if used it must be place at top of document.

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

RULES FOR XML SYNTAX DECLARATION

  • If  document contains a XML declaration then it must be first statement of the document.
  • XML declaration is case – sensitive, where document begins with <?xml>. “xml” is in lower case.
  • An HTTP protocol can override the value of encoding that you put in the XML declaration.

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

SYNTAX RULES  FOR ELEMENTS AND TAGS

Element Syntax: every XML-element must be closed either with begin or with finish components as shown below:

<element>....</element>

or just by this technique:

<element/>

Nested elements: An XML element can contain other XML- elements as its child, but the children elements must not overlap it parent element. i.e., an end tag of an element must have the same tag name as that of the most recent unmatched start tag.

example for incorrect nested tags:

    <?xml version="1.0"?>
    <author>
    <name>syntax definition
    </author>
    </name>

example for correct nested tags:

    <?xml version="1.0"?>
    <author>
    <name>syntax definition
    </name>
    </author>

Root element: An XML document must have and can have only one root element. For example, following example is not a correct XML document, because both the a and b elements occur at the top level without a root element:

    <a>...</a>
    <b>...</b>

The correct form of XML document is:

    <root>
     <a>...</a>
     <b>...</b>
    </root>
    or
    <a>
     <b>...</b>
    </a>

Case sensitivity: The tag names of XML-elements are case-sensitive. This means that the name of the starting and the ending elements should be exactly in the same case.

For example <Syntax> is different from <syntax>.

Tags:
xml
0
Rating
1 2 3 4 5

Save

Saved

Report

Reported
Reasons
Cancel
0 comments