What is XML Parser When creating XML document

  • Slides: 10
Download presentation
What is XML Parser?

What is XML Parser?

ü When creating XML document, you need to ensure that document is well-formed and

ü When creating XML document, you need to ensure that document is well-formed and valid. ü An XML parser provides two types of checks for an XML document. (i) Whether an XML document is well-formed or not. (ii) Whether an XML document is valid or not.

Well-Formed XML document

Well-Formed XML document

ü A well-formed XML document must have: (i) A Root Element EXAMPLE 1: EXAMPLE

ü A well-formed XML document must have: (i) A Root Element EXAMPLE 1: EXAMPLE 2: <countries> <country-name> India </country-name> <capital> Delhi </capital> <country-name> USA </country-name> <capital> Washing ton </capital> </countries>

ü A well-formed XML document must have: (ii) opening and Ending tag i. e

ü A well-formed XML document must have: (ii) opening and Ending tag i. e For every opening tag there should be ending tag EXAMPLE 1: <countries> EXAMPLE 2: <countries> <country-name> India </country-name> <capital> Delhi </capital> <country-name> USA </country-name> <capital> Washing ton </capital> <capital> Washing ton </countries>

ü A well-formed XML document must have: (iii) Appropriate Nesting EXAMPLE 1: EXAMPLE 2:

ü A well-formed XML document must have: (iii) Appropriate Nesting EXAMPLE 1: EXAMPLE 2: <vegetables> <leafy> <name> Spinach </leafy> </name> </vegetables> <name> Spinach </leafy> </vegetables> </name>

ü A well-formed XML document must have: (iv) Values always enclosed in quotation marks.

ü A well-formed XML document must have: (iv) Values always enclosed in quotation marks. EXAMPLE 1: <countries> India</country-name> <country-name id=“ 1”> <capital> Delhi </capital> <country-name id=“ 2”>USA</country-name> <capital> Washing ton</capital> </countries> EXAMPLE 2: <countries> <country-name id=1>India</country-name> <capital>Delhi </capital> <country-name id=2>USA</country-name> <capital>Washing ton</capital> </countries>

ü A well-formed XML document must have: (v) Matching of tags. EXAMPLE 1: <countries>

ü A well-formed XML document must have: (v) Matching of tags. EXAMPLE 1: <countries> EXAMPLE 2: <countries> <country-name> India </countrie-name> <country-name> India </country-name> <capital> Delhi </capital> <country-name> USA </country-name> <capital> Washing ton </capitale> </COUNTRIES> </countryies>

Valid XML document

Valid XML document

ü An XML document is valid if: (i) it is well-formed document. (ii) it

ü An XML document is valid if: (i) it is well-formed document. (ii) it should conform(match, comply) to the rules specified in DTD.