support Click to see our new support page.
support For sales enquiry!

XML Coding Standards

XML Coding Standards

Sahdiya MammoottyOct. 5, 2019

eXtensible Markup Language-XML

XML file is an extension for Extensible Markup Language file format. XML was design to store and transport data. It was also design to be both human- and machine-readable.

The Difference Between XML and HTML

XML and HTML were design with different goals:

  • XML (Extensible Markup Language ) was design to carry data - that is, with a focus on what data is.
  • HTML (Hypertext Markup Language ) was design to display data - that is, with a focus on how data looks.
  • Furthermore, XML tags are not predefine like HTML tags are.

The Important XML standards are;



XML DTD-XMLFile Type Definition/Declaration

  • Use to describe XML file Language precisely.
  • Use to define the structure of an XML document.
  • Contain the list of legal element.
  • It is also perform validation.


<!DOCTYPE element DTD identifier[declaration1 declaration2]>

Types of DTD

INTERNAL DTD: Elements are define within the XML files.


<!DOCTYPE root-element[element-declaration]>


<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT heading (#PCDATA)>
<body>Don't forget me this weekend</body>

EXTERNAL DTD: Elements are declare outside the files.


<!DOCTYPE root-element SYSTEM “file-name”>


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



  • It is use to avoid element name conflict.
  • It is a set of unique name.
  • Identified by URI ( Uniform Resource Identifier ).
  • Attributes name start with “xmlns” name.


<element xmlns:name “URL”>


Generally Conflict occurs when we try to mix documents from different xml application.

Example of conflict:





Here conflict occurs due to the same element name.


Solving the Name Conflict Using a Prefix:

Name conflicts in XML (Extensible Markup Language) file can easily be avoided using a name prefix.

This carries information about an HTML table, and a piece of furniture:

<f:name>African Coffee Table</f:name>

So, in the above example there will be no conflict, because the two <table> elements have different names.

When using prefixes, a namespace for the prefix must be defined. The namespace can be defined by an xmlns attribute in the start tag of an element. The namespace declaration has the following syntax: xmlns:prefix="URI".

XML DOM-(Document Object Model)


  • DOM is the Document object model.
  • The DOM defines a standard way for accessing and manipulating.
  • XML file documents like xml and html.
  • The DOM is a W3C(World Wide Web) standard.
  • The DOM is memory based, that is, which makes  it traversable and also editable.
  • DOM is not language specific, nor is it platform specific.



  • A standard Object model.
  • The W3C(World Wide Web) standard.
  • A standard programming interface for xmlPlatform and also language independent.

The DOM defines a standard for accessing and manipulating documents:

“The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.”

The HTML DOM defines a standard way for accessing and manipulating HTML documents. It presents an HTML document as a tree-structure. The XML DOM defines a standard way for accessing and manipulating XML documents. It also presents an XML file document as a tree-structure. All HTML elements can be access through the HTML DOM.

According to the XML DOM, everything in an XML file document is a node:

  • The entire document is a document node.
  • Every XML(Extensible Markup Language) element is an element node.
  • The text in the elements are text nodes.
  • Every attribute is an attribute node.
  • Also every comments are comment nodes.


<?xml version="1.0" encoding="UTF-8"?>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>



XML DOM property

The property is used to get all the details about the nodes. Some of the DOM property is shown below;

  • x.nodeName - the name of x
  • x.nodeValue - the Value of x
  • x.parentNode - the parent node of x
  • x.childNodes - the child node of x
  • X.attribute - the attribute node of x
    Where ‘x’ is a node object.



  • x.getElementsByTagName(name); - get all elements with a specified tag name
  • x.appendchild(node); - insert a child node to x
  • x.removechild(node); - remove a child node from x
    Where ‘x’ is a node object.



  • xmlDoc-the XML DOM object
  • xmlDoc.getElementsByTagname(“title”)[0] - the first <title> element
  • Childnodes[0] - the first child of the <title> element (the text node)
  • NodeValue - the value of the node (the text itself)



  • Extensible Markup Language structure is traversable.
    That is, each node can be randomly accessed(one or more times) by traversing the tree.
  • Structure is modifiable.
    Since the XML file structure is resident in memory, values can be added, changed, and removed.
  • The DOM standard is maintained by the word wide web consortium.



  • Resource Intensive
    Since the XML structure is resident in memory the larger the XML structure is, the more memory it will consume.
  • Relative Speed
    In comparison to SAX, DOM can be much slower due to its resource usage/needs.



  • It defines a standard way for accessing and manipulating XML Document.
  • The DOM presents an XML file document as a structure.
  • Knowing it makes work easier with XML file.


  • XPath is a major element in the XSLT standard.
  • It can be used to navigate through elements and also the attributes in an XML document.
  • XPath is a syntax for defining parts of an XML document.
  • It uses path expressions to navigate in XML documents.
  • It contains a library of standard functions.
  • XPath is a major element in XSLT and XQuery.
  • It is a W3C recommendation.

extensible markup language-xpath

XPath Path Expressions: XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system.
XPath is also used in XSLT. XPath is a major element in the XSLT standard. So, with XPath knowledge you will be able to take great advantage of XSL.

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

<title>Harry Potter</title>
<author>J K. Rowling</author>

<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>


XPath Nodes: In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes. XML documents are treated as trees of nodes. That is, the topmost element of the tree is called the root element.

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

<bookstore> <!--root element node-->
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author> <!--element node-->

Relationship of Nodes:

1) Parent:
Each element and attribute has one parent.

In the following example; the book element is the parent of the title, author, year, and price.

<title>Harry Potter</title>
<author>J K. Rowling</author>

2) Children:

Element nodes may have zero, one or more children.

In the above example; the title,author, year, and price elements are all children of the book element.

3) Siblings:

Nodes that have the same parent.

In the above example; the title, author, year, and price elements are all siblings.

4) Ancestors:

A node's parent, parent's parent, etc.

In the following example; the ancestors of the title element are the book element and the bookstore element.

5) Descendants:

A node's children, children's children, etc.

In the following example; descendants of the bookstore element are the book, title, author, year, and also price elements.

XPath Syntax: XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps.

XPath Axes: An axis represents a relationship to the context (current) node, and is used to locate nodes relative to that node on the tree.

Location Path Expression: A location path can be absolute or relative. An absolute location path starts with a slash ( / ) and a relative location path does not. In both cases, the location path consists of one or more steps, each separated by a slash.

An absolute location path:


A relative location path:


Each step is evaluated against the nodes in the current node-set.

A step consists of:

  • an axis (defines the tree-relationship between the selected nodes and the current node)
  • a node-test (identifies a node within an axis)
  • zero or more predicates (to further refine the selected node-set)

The syntax for a location step is:


XML XSLT - eXtensible Style-sheet Language Translations.

With XSLT you can transform an XML document into HTML.

Displaying XML with XSLT:

XSLT (eXtensible Stylesheet Language Transformations) is the recommended style sheet language for XML.

XSLT is far more sophisticated than CSS. With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which element to hide and display, and a lot more.

XSLT uses XPath to find information in an XML document.


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

<name>Belgian Waffles</name>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>

<name>Berry-Berry Belgian Waffles</name>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>

<name>French Toast</name>
<description>Thick slices made from our homemade sourdough bread</description>


Use XSLT to transform XML into HTML, before it is displayed in a browser.

Example of XSLT style-sheet:

<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="breakfast_menu/food">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"><xsl:value-of select="name"/> - </span>
<xsl:value-of select="price"/>
<div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
<xsl:value-of select="description"/>
<span style="font-style:italic"> (<xsl:value-of select="calories"/> calories per serving)</span>


XML and XQuery

XQuery is:

  • XQuery is to XML what SQL is to databases.
  • It was designed to query XML data.
  • It is a language for querying XML data.
  • XQuery for XML is like SQL for databases.
  • It is built on XPath expressions.
  • It is also supported by all major databases.
  • XQuery is a W3C Recommendation.

extensible markup language-xquery

Example of XQuery:

for $x in doc("books.xml")/bookstore/book
where $x/price>30
order by $x/title
return $x/title

XQuery is About Querying XML:-XQuery is a language for finding and extracting elements and attributes from XML documents.
Here is an example of what XQuery could solve:

"Select all CD records with a price less than $10 from the CD collection stored in cd_catalog.xml".

XQuery and XPath:-XQuery 1.0 and XPath 2.0 share the same data model and support the same functions and operators. If you have already studied XPath you will have no problems with understanding XQuery.

XQuery can be use to:

  • Extract information to use in a Web Service.
  • Can also generate summary reports
  • Transform XML data to XHTML
  • It also search Web documents for relevant information


XML, XLink and XPointer

XLink is use to create hyperlinks in XML documents.

  • XLink is use to create hyperlinks within XML documents.
  • Any element in an XML document can behave as a link.
  • With XLink, the links can be define outside the linked files.
  • XLink is also a W3C Recommendation.

extensible markup language- xlink

XLink Syntax:- In HTML, the <a> element defines a hyperlink. However, this is not how it works in XML. In XML documents, you can use whatever element names you want - therefore it is impossible for browsers to predict what link elements will be called in XML documents.

Example of how to use XLink to create links in an XML document:

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

<homepages xmlns:xlink="">
<homepage xlink:type="simple" xlink:href="">Visit W3Schools</homepage>
<homepage xlink:type="simple" xlink:href="">Visit W3C</homepage>
  • To get access to the XLink features we must declare the XLink namespace. The XLink namespace is: "".
  • The xlink:type and the xlink:href attributes in the <homepage> elements come from the XLink namespace.
  • The xlink:type="simple" creates a simple "HTML-like" link (means "click here to go there").
  • The xlink:href attribute specifies the URL to link to.


XLink - Going Further:-

In the example above we have demonstrated simple XLinks. XLink is getting more interesting when accessing remote locations as resources, instead of standalone pages.

If we set the value of the xlink:show attribute to "embed", the linked resource should be processed inline within the page. When you consider that this could be another XML document you could, for example, build a hierarchy of XML documents.

You can also specify WHEN the resource should appear, with the xlink:actuate attribute.


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

<bookstore xmlns:xlink="">

<book title="Harry Potter">
As his fifth year at Hogwarts School of Witchcraft and
Wizardry approaches, 15-year-old Harry Potter is.......

<book title="XQuery Kick Start">
XQuery Kick Start delivers a concise introduction
to the XQuery standard.......


  • XPointer allows links to point to specific parts of an XML document.
  • It uses XPath expressions to navigate in the XML document.
  • Likewise XLINK , it is a W3C Recommendation.


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


<dog breed="Rottweiler" id="Rottweiler">
<picture url="" />
<history>The Rottweiler's ancestors were probably Roman
drover dogs.....</history>
<temperament>Confident, bold, alert and imposing, the Rottweiler
is a popular choice for its ability to protect....</temperament>

<dog breed="FCRetriever" id="FCRetriever">
<picture url="" />
<history>One of the earliest uses of retrieving dogs was to
help fishermen retrieve fish from the water....</history>
<temperament>The flat-coated retriever is a sweet, exuberant,
lively dog that loves to play and retrieve....</temperament>


Note that the XML document above also uses id attributes on each element!

So, instead of linking to the entire document (as with XLink), XPointer allows you to link to specific parts of the document. To link to a specific part of a page, add a number sign (#) and an XPointer expression after the URL in the xlink:href attribute, like this: xlink:href="'Rottweiler'))". The expression refers to the element in the target document, with the id value of "Rottweiler".

XPointer also allows a shorthand method for linking to an element with an id. You can use the value of the id directly, like this: xlink:href="".

XML schema

  • An XML Schema describes the structure of an XML document, just like a DTD.
  • Document with correct syntax is called "Well Formed".
  • Document validated against an XML Schema is both "Well Formed" and also "Valid".

XML Schema is an XML-based alternative to DTD.


<xs:element name="note">

<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>




  • XML Schemas are written in XML.
  • It will be extensible to additions.
  • They also support data types.
  • They also support namespaces.


XML Schemas use XML Syntax

Another great strength about XML Schemas is that they are written in XML:

  • Don't have to learn a new language.
  • Can also use your XML editor to edit your Schema files.
  • Can also use your XML parser to parse your Schema files.
  • You can also manipulate your Schemas.
  • You can also transform your Schemas with XSLT.


LinkedIn LinkedIn

Leave a Comment