SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Understanding
  XML DOM
(W3C Standard)

         Created by :
         Om Vikram Thapa
INDEX :
   XML DOM – Introduction
   DOM Nodes (Tree Structure)
   DOM Parsing
   DOM Load Functions (in IE & FireFox)
   DOM Properties & Methods
   DOM HttpRequest
   DOM Node Types
   DOM Parse Error Objects
   Thank You!!
XML DOM (INTRODUCTION)
 The XML DOM (Document Object Model) defines a standard
   way for accessing and manipulating XML documents.

 The DOM is a W3C (World Wide Web Consortium) standard.

 DOM defines the objects and properties and methods (interface)
   to access all XML elements.

 The DOM presents an XML document as a tree structure, with
   elements, attributes, and text as nodes.

 The DOM is separated into 3 different parts / levels:
   Core DOM - standard model for any structured document
   XML DOM - standard model for XML documents
   HTML DOM - standard model for HTML documents
What is an XML DOM?
 The XML DOM is:
  - A standard object model for XML
  - A standard programming interface for XML
  - Platform and language-independent
  - A W3C standard
 The XML DOM defines the objects and properties
  of all XML elements, and the methods (interface) to
  access them.
 The XML DOM is a standard for how to get, change,
  add or delete XML elements.
AN EXAMPLE OF books.xml:
<bookstore>
- <book category="cooking">
 <title lang="en">Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
 <price>30.00</price>
 </book>
- <book category="language">
  <title lang="en">English</title>
 <author>Om Vikram</author>
  <year>2005</year>
  <price>50.00</price>
  </book>
  </bookstore>
XML DOM NODES :
DOM NODES DESCRIPTION
 According to the DOM, everything in an XML
   document is a node.
 The entire document is a document node .
 Every XML element is an element node .
 The text in the XML elements are text nodes .
 Every attribute is an attribute node .
 Comments are comment nodes.
In our ex.
- The root node <bookstore> holds four <book> nodes.
- Each <book> node contain 4 text node i.e.
  <title>, <author>, <year>, and <price>
XML DOM PARSING:
 Most browsers have a build-in XML parser to read
    and manipulate XML.
   The parser reads XML into memory and converts
    XML it into XML DOM object which is accessible
    from JavaScript .
   There are some differences between Microsoft's
    XML parser and the parsers used in other browsers.
   The MS parser supports loading of both XML files
    and XML strings (text)
   Other browsers use Separate parsers.
   However, all parsers contain functions to traverse
    XML trees, access, insert, and delete nodes.
Loading XML with IE using MS
XML Parser:
 The following JavaScript fragment loads an XML
  document “book.xml” into the parser :
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.load("books.xml");


 The following JavaScript fragment loads an XML text
  into the parser :
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(txt);
Loading XML with FireFox & Other
 XML Parser :
 The following JavaScript fragment loads an XML
  document “book.xml” into the parser :

  xmlDoc=document.implementation.createDocument("","",null)
  ;
  xmlDoc.async="false";
  xmlDoc.load("books.xml");


 The following JavaScript fragment loads an XML text
  into the parser :
   parser=new DOMParser();
   xmlDoc=parser.parseFromString(txt,"text/xml");
DOM PROPERTIES & METHODS:
 XML DOM Properties:
    x.nodeName - the name of x
    x.nodeValue - the value of x
    x.parentNode - the parent node of x
    x.childNodes - the child nodes of x
    x.attributes - the attributes nodes of x
                     (where x is a node object. )
 XML DOM Methods:
      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
AN EXAMPLE :
txt=xmlObj.getElementsByTagName("title")[0].childNodes[0].nodeValue;

where
 xmlObj - the XML DOM object created by the parser.
 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)
NODE TYPES
NodeTypes   Named Constants
    1      ELEMENT_NODE
    2      ATTRIBUTE_NODE
    3      TEXT_NODE
    4      CDATA_SECTION_NODE
    5      ENTITY_REFERENCE_NODE
    6      ENTITY_NODE
    7      PROCESSING_INSTRUCTION_NODE
    8      COMMENT_NODE
    9      DOCUMENT_NODE
    10     DOCUMENT_TYPE_NODE
    11     DOCUMENT_FRAGMENT_NODE
    12     NOTATION_NODE
DOM PARSE ERROR OBJECTS
 When trying to open an XML document, a parser-error may
    occur.
   With the parseError object, you can retrieve the error code, the
    error text, the line that caused the error, and more.
    Property       Description
   errorCode Returns a long integer error code
   Reason         Returns a string containing the reason for the error
   Line           Returns a long integer representing the line
                   number for the error
   Linepos        Returns a long integer representing the line
                   position for the error
   srcText        Returns a string containing the line that caused the
                   error
   url            Returns the URL pointing the loaded document
   Filepos        Returns a long integer file position of the error
THANK YOU !!

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Dom
Dom Dom
Dom
 
XML
XMLXML
XML
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Xml ppt
Xml pptXml ppt
Xml ppt
 
XML
XMLXML
XML
 
Html formatting
Html formattingHtml formatting
Html formatting
 
Basic html
Basic htmlBasic html
Basic html
 
Css selectors
Css selectorsCss selectors
Css selectors
 
Dom
DomDom
Dom
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Xml presentation
Xml presentationXml presentation
Xml presentation
 
Form Handling using PHP
Form Handling using PHPForm Handling using PHP
Form Handling using PHP
 
Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basics
 
Dhtml ppt (2)
Dhtml ppt (2)Dhtml ppt (2)
Dhtml ppt (2)
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
Xml dom
Xml domXml dom
Xml dom
 
DTD
DTDDTD
DTD
 
Html coding
Html codingHtml coding
Html coding
 
Basic Details of HTML and CSS.pdf
Basic Details of HTML and CSS.pdfBasic Details of HTML and CSS.pdf
Basic Details of HTML and CSS.pdf
 

Andere mochten auch (17)

An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
XML and XPath details
XML and XPath detailsXML and XPath details
XML and XPath details
 
Xpath presentation
Xpath presentationXpath presentation
Xpath presentation
 
Xpath
XpathXpath
Xpath
 
Xml parsing
Xml parsingXml parsing
Xml parsing
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
 
XSLT
XSLTXSLT
XSLT
 
Parsing XML Data
Parsing XML DataParsing XML Data
Parsing XML Data
 
Overview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOOverview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FO
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
XML DOM
XML DOMXML DOM
XML DOM
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
 
XSLT
XSLTXSLT
XSLT
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
XML/XSLT
XML/XSLTXML/XSLT
XML/XSLT
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
DOM and SAX
DOM and SAXDOM and SAX
DOM and SAX
 

Ähnlich wie Understanding XML DOM

Ähnlich wie Understanding XML DOM (20)

Xml nisha dwivedi
Xml nisha dwivediXml nisha dwivedi
Xml nisha dwivedi
 
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Xml
XmlXml
Xml
 
Part 7
Part 7Part 7
Part 7
 
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web TechnologyInternet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
 
XML
XMLXML
XML
 
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
 
Xml writers
Xml writersXml writers
Xml writers
 
Unit 2
Unit 2 Unit 2
Unit 2
 
Xml session
Xml sessionXml session
Xml session
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
 
The xml
The xmlThe xml
The xml
 
[DSBW Spring 2010] Unit 10: XML and Web And beyond
[DSBW Spring 2010] Unit 10: XML and Web And beyond[DSBW Spring 2010] Unit 10: XML and Web And beyond
[DSBW Spring 2010] Unit 10: XML and Web And beyond
 
Ch23
Ch23Ch23
Ch23
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_java
 
advDBMS_XML.pptx
advDBMS_XML.pptxadvDBMS_XML.pptx
advDBMS_XML.pptx
 
DOM Quick Overview
DOM Quick OverviewDOM Quick Overview
DOM Quick Overview
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.net
 
DATA INTEGRATION (Gaining Access to Diverse Data).ppt
DATA INTEGRATION (Gaining Access to Diverse Data).pptDATA INTEGRATION (Gaining Access to Diverse Data).ppt
DATA INTEGRATION (Gaining Access to Diverse Data).ppt
 

Mehr von Om Vikram Thapa

Mehr von Om Vikram Thapa (20)

Next Set of Leaders Series
Next Set of Leaders SeriesNext Set of Leaders Series
Next Set of Leaders Series
 
Integration Testing at go-mmt
Integration Testing at go-mmtIntegration Testing at go-mmt
Integration Testing at go-mmt
 
Understanding payments
Understanding paymentsUnderstanding payments
Understanding payments
 
System Alerting & Monitoring
System Alerting & MonitoringSystem Alerting & Monitoring
System Alerting & Monitoring
 
Serverless computing
Serverless computingServerless computing
Serverless computing
 
Sumologic Community
Sumologic CommunitySumologic Community
Sumologic Community
 
Postman Integration Testing
Postman Integration TestingPostman Integration Testing
Postman Integration Testing
 
Scalibility
ScalibilityScalibility
Scalibility
 
5 Dysfunctions of a team
5 Dysfunctions of a team5 Dysfunctions of a team
5 Dysfunctions of a team
 
AWS Must Know
AWS Must KnowAWS Must Know
AWS Must Know
 
Continuous Feedback
Continuous FeedbackContinuous Feedback
Continuous Feedback
 
Sql views, stored procedure, functions
Sql views, stored procedure, functionsSql views, stored procedure, functions
Sql views, stored procedure, functions
 
Confluence + jira together
Confluence + jira togetherConfluence + jira together
Confluence + jira together
 
Understanding WhatFix
Understanding WhatFixUnderstanding WhatFix
Understanding WhatFix
 
Tech Recruitment Process
Tech Recruitment Process Tech Recruitment Process
Tech Recruitment Process
 
Jira Workshop
Jira WorkshopJira Workshop
Jira Workshop
 
Security@ecommerce
Security@ecommerceSecurity@ecommerce
Security@ecommerce
 
Understanding iis part2
Understanding iis part2Understanding iis part2
Understanding iis part2
 
Understanding iis part1
Understanding iis part1Understanding iis part1
Understanding iis part1
 
.Net framework
.Net framework.Net framework
.Net framework
 

Kürzlich hochgeladen

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

Understanding XML DOM

  • 1. Understanding XML DOM (W3C Standard) Created by : Om Vikram Thapa
  • 2. INDEX :  XML DOM – Introduction  DOM Nodes (Tree Structure)  DOM Parsing  DOM Load Functions (in IE & FireFox)  DOM Properties & Methods  DOM HttpRequest  DOM Node Types  DOM Parse Error Objects  Thank You!!
  • 3. XML DOM (INTRODUCTION)  The XML DOM (Document Object Model) defines a standard way for accessing and manipulating XML documents.  The DOM is a W3C (World Wide Web Consortium) standard.  DOM defines the objects and properties and methods (interface) to access all XML elements.  The DOM presents an XML document as a tree structure, with elements, attributes, and text as nodes.  The DOM is separated into 3 different parts / levels: Core DOM - standard model for any structured document XML DOM - standard model for XML documents HTML DOM - standard model for HTML documents
  • 4. What is an XML DOM?  The XML DOM is: - A standard object model for XML - A standard programming interface for XML - Platform and language-independent - A W3C standard  The XML DOM defines the objects and properties of all XML elements, and the methods (interface) to access them.  The XML DOM is a standard for how to get, change, add or delete XML elements.
  • 5. AN EXAMPLE OF books.xml: <bookstore> - <book category="cooking"> <title lang="en">Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> - <book category="language"> <title lang="en">English</title> <author>Om Vikram</author> <year>2005</year> <price>50.00</price> </book> </bookstore>
  • 7. DOM NODES DESCRIPTION  According to the DOM, everything in an XML document is a node.  The entire document is a document node .  Every XML element is an element node .  The text in the XML elements are text nodes .  Every attribute is an attribute node .  Comments are comment nodes. In our ex. - The root node <bookstore> holds four <book> nodes. - Each <book> node contain 4 text node i.e. <title>, <author>, <year>, and <price>
  • 8. XML DOM PARSING:  Most browsers have a build-in XML parser to read and manipulate XML.  The parser reads XML into memory and converts XML it into XML DOM object which is accessible from JavaScript .  There are some differences between Microsoft's XML parser and the parsers used in other browsers.  The MS parser supports loading of both XML files and XML strings (text)  Other browsers use Separate parsers.  However, all parsers contain functions to traverse XML trees, access, insert, and delete nodes.
  • 9. Loading XML with IE using MS XML Parser:  The following JavaScript fragment loads an XML document “book.xml” into the parser : xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load("books.xml");  The following JavaScript fragment loads an XML text into the parser : xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(txt);
  • 10. Loading XML with FireFox & Other XML Parser :  The following JavaScript fragment loads an XML document “book.xml” into the parser : xmlDoc=document.implementation.createDocument("","",null) ; xmlDoc.async="false"; xmlDoc.load("books.xml");  The following JavaScript fragment loads an XML text into the parser : parser=new DOMParser(); xmlDoc=parser.parseFromString(txt,"text/xml");
  • 11. DOM PROPERTIES & METHODS:  XML DOM Properties:  x.nodeName - the name of x  x.nodeValue - the value of x  x.parentNode - the parent node of x  x.childNodes - the child nodes of x  x.attributes - the attributes nodes of x (where x is a node object. )  XML DOM Methods:  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
  • 12. AN EXAMPLE : txt=xmlObj.getElementsByTagName("title")[0].childNodes[0].nodeValue; where  xmlObj - the XML DOM object created by the parser.  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)
  • 13. NODE TYPES NodeTypes Named Constants  1 ELEMENT_NODE  2 ATTRIBUTE_NODE  3 TEXT_NODE  4 CDATA_SECTION_NODE  5 ENTITY_REFERENCE_NODE  6 ENTITY_NODE  7 PROCESSING_INSTRUCTION_NODE  8 COMMENT_NODE  9 DOCUMENT_NODE  10 DOCUMENT_TYPE_NODE  11 DOCUMENT_FRAGMENT_NODE  12 NOTATION_NODE
  • 14. DOM PARSE ERROR OBJECTS  When trying to open an XML document, a parser-error may occur.  With the parseError object, you can retrieve the error code, the error text, the line that caused the error, and more. Property Description  errorCode Returns a long integer error code  Reason Returns a string containing the reason for the error  Line Returns a long integer representing the line number for the error  Linepos Returns a long integer representing the line position for the error  srcText Returns a string containing the line that caused the error  url Returns the URL pointing the loaded document  Filepos Returns a long integer file position of the error