SlideShare une entreprise Scribd logo
1  sur  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 !!

Contenu connexe

Tendances

Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
yht4ever
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 

Tendances (20)

XML Schema
XML SchemaXML Schema
XML Schema
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
02 well formed and valid documents
02 well formed and valid documents02 well formed and valid documents
02 well formed and valid documents
 
Xpath presentation
Xpath presentationXpath presentation
Xpath presentation
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Xml schema
Xml schemaXml schema
Xml schema
 
Json
JsonJson
Json
 
XQuery
XQueryXQuery
XQuery
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Xml
XmlXml
Xml
 
Introduction to the DOM
Introduction to the DOMIntroduction to the DOM
Introduction to the DOM
 
Xml ppt
Xml pptXml ppt
Xml ppt
 
XML
XMLXML
XML
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
XML Introduction
XML IntroductionXML Introduction
XML Introduction
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Java script
Java scriptJava script
Java script
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 

En vedette (17)

XML and XPath details
XML and XPath detailsXML and XPath details
XML and XPath details
 
Dom
Dom Dom
Dom
 
Xpath
XpathXpath
Xpath
 
Document object model
Document object modelDocument object model
Document object model
 
Xml parsing
Xml parsingXml parsing
Xml parsing
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
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
 
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
 

Similaire à Understanding XML DOM

java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
Surinder Kaur
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.net
glubox
 

Similaire à 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
 
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
 
CTDA Workshop on XML and MODS
CTDA Workshop on XML and MODSCTDA Workshop on XML and MODS
CTDA Workshop on XML and MODS
 

Plus de Om Vikram Thapa

Plus de 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
 

Dernier

Dernier (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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

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