How to use Validation in XML

In this article I am going to explain about XML validation.
  • 1607

XML Validation

XML is mark up language like HTML. It is case sensitive language so it is very necessary different between Capital and small at the time of writing XML code.  XML has some rule that must be follow.

  • An XML document must have a root element.
  • In XML document every element have must be closed tag.
  • Every element must be nested.
  • Attributed values must be quoted.
  • XML tag are case sensitive.
  • In XML we can create own type tag.

An valid XML Document

<?xml version="1.0" encoding="iso-8859-1"?>

<root>

  <Name>Prabhat</Name>

  <Add>Delhi</Add>

  <Company>MCN solution</Company>

  <Salary>10000</Salary>

</root>

XML DTD

XML DTD stands for XML Document type definition. The purpose of DTD Its define the structure of XML element its also define the legal element in XML document with structure.

<!DOCTYPE root

[

  <!ELEMENT root (Name,Add,Company,Salary)>

  <!ELEMENT Name (#PCDATA)>

  <!ELEMENT Add (#PCDATA)>

  <!ELEMENT Company (#PCDATA)>

  <!ELEMENT Salary (#PCDATA)>

]>

XML Schema

<xs:element name="root">

 

  <xs:complexType>

    <xs:sequence>

      <xs:element name="Name" type="xs:string"/>

      <xs:element name="Add" type="xs:string"/>

      <xs:element name="Company" type="xs:string"/>

      <xs:element name="Salary" type="xs:string"/>

    </xs:sequence>

  </xs:complexType>

 

</xs:element>

Further Readings

You may also want to read these related articles: here
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

 

© 2019 DotNetHeaven. All rights reserved.