Download presentation
Presentation is loading. Please wait.
Published byJason Preston Modified over 9 years ago
1
XML Document Object Model Anthony Borquez
2
The Document Object Model a programming interface for HTML and XML documents. It defines the way a document can be accessed and manipulated. Using a DOM, a programmer can create a document, navigate its structure, and add, modify, or delete its elements. The W3C DOM has been designed to be used with any programming language. provides a standard programming interface that can be used in a wide variety of environments and applications.
3
The Node Interface XML parser can be used to load an XML document into the memory of your compute information can be retrieved and manipulated by accessing the Document Object Model (DOM). The DOM represents a tree view of the XML document The documentElement is the top-level of the tree This element has one or many childNodes that represent the branches of the tree
4
A Node Interface is used to read and write (or access if you like) the individual elements in the XML node tree The childNodes property of the documentElement can be accesses with a for/each construct to enumerate each individual node
5
XML DOM Parser: language-neutral programming model Supports JavaScript, VBScript, Perl, VB, Java, C++ and more Supports W3C XML 1.0 and XML DOM Supports DTD and validation
6
JavaScript in IE 5.0 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") VBScript set xmlDoc = CreateObject("Microsoft.XMLDOM") ASP set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
7
Loading an XML file into the parser var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("note.xml") //....... processing the document goes here
8
Loading pure XML text into the parser var text=" “ text=text+" Tove Jani “ text=text+" Reminder “ text=text+" Don't forget me this weekend! " text=text+" " var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.loadXML(text) //....... processing the document goes here
9
The parseError Object var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("ksdjf.xml") document.write(" Error Code: ") document.write(xmlDoc.parseError.errorCode) document.write(" Error Reason: ") document.write(xmlDoc.parseError.reason) document.write(" Error Line: ") document.write(xmlDoc.parseError.line)
10
XML Error var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("note_error.xml") document.write(" Error Code: ") document.write(xmlDoc.parseError.errorCode) document.write(" Error Reason: ") document.write(xmlDoc.parseError.reason) document.write(" Error Line: ") document.write(xmlDoc.parseError.line)
11
The parseError Properties errorCode Returns a long integer error code Reason Returns a string explaining the reason for the error LineReturns a long integer representing the line number for the error linePosReturns a long integer representing the line position for the error srcTextReturns a string containing the line that caused the error urlReturns the url pointing the loaded document filePosReturns a long integer file position of the error
12
Traversing the node tree set xmlDoc=CreateObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("note.xml") for each x in xmlDoc.documentElement.childNodes document.write(x.nodename) document.write(": ") document.write(x.text) next
13
Providing HTML content from XML files XML can separate HTML documents from their data var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("note.xml") nodes = xmlDoc.documentElement.childNodes to.innerText = nodes.item(0).text from.innerText = nodes.item(1).text header.innerText = nodes.item(2).text body.innerText = nodes.item(3).text
14
Accessing XML elements by name var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false“ xmlDoc.load("note.xml") document.write(xmlDoc.getElementsByTagName("from").item(0).t ext)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.