cis 375—web app dev ii dom. 2 introduction to dom the xml document ________ model (dom) is a...
TRANSCRIPT
![Page 1: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/1.jpg)
CIS 375—Web App Dev II
DOM
![Page 2: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/2.jpg)
2
Introduction to DOM The XML Document ________ Model (DOM) is a
programming interface for XML documents. It defines the way an XML document can be
accessed and _____________. The XML DOM is designed to be used with any
programming language and any __________ system.
The DOM represents a ______ view of the XML document.
The documentElement is the top-level of the tree. This element has one or many ___________ that
represent the branches of the tree.
![Page 3: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/3.jpg)
3
Common Node TypesNode Type Example
Document type
<!DOCTYPE food SYSTEM "food.dtd">
Processing instruction
<?xml version="1.0"?>
Element <drink type="beer">Carlsberg</drink>
Attribute type="beer“
Text Carlsberg
![Page 4: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/4.jpg)
4
Parsing the DOM The Microsoft XML _______ is a COM
component that comes with Microsoft Internet Explorer 5.0.
The Microsoft XMLDOM parser: Supports JavaScript, VBScript, Perl, VB, Java, C++,
… Supports W3C XML 1.0 and XML DOM Supports DTD and validation
Creating an XML document object using JavaScript, _________, and VBScript in ASP:var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
set xmlDoc = CreateObject("Microsoft.XMLDOM")
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
![Page 5: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/5.jpg)
5
Loading XML Files and Text
Loading a file<script type="text/javascript"> var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")xmlDoc.async="false" xmlDoc.load("note.xml") // ....... processing the document goes here
</script> Loading text (see example)
<script type="text/javascript"> var text="<note>“text=text+"<to>Tove</to><from>Jani</from>“text=text+"<heading>Reminder</heading>“text=text+"<body>Don't forget me this weekend!</body>“text=text+"</note>" var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")xmlDoc.async="false" xmlDoc.loadXML(text) // ....... processing the document goes here </script>
![Page 6: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/6.jpg)
6
Parser Errors The parseError _______ can be used to extract
error information from the Microsoft XML parser, but is not a part of the W3C DOM standard.
The following ___________ code accesses the parseError object:var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("note_error.xml") document.write("<br>Error Code: ") document.write(xmlDoc.parseError.errorCode) document.write("<br>Error Reason: ") document.write(xmlDoc.parseError.reason) document.write("<br>Error Line: ") document.write(xmlDoc.parseError.line)
Try it Yourself or just look at the XML file
![Page 7: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/7.jpg)
7
DOM Validator To help you validate your xml, w3schools has
used Microsoft's XML parser to create an xml validator.
Paste your XML in the text area, and validate it by pressing the validate button.
You can also validate your XML files simply by typing the URL of your XML file and pressing the submit button.
NOTE: If you get an error when accessing this file, it is because your IE security settings do not allow access across domains. To correct, select Tools, Internet Options, Security, Custom Level…,
Miscellaneous, Access data sources across domains
![Page 8: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/8.jpg)
8
Accessing the DOM The following VBScript code examples
traverse an XML node _____, and display the XML elements in the browser: JUST TRY IT and also try the CD catalog example
The following JavaScript reads XML data from an XML document and writes the XML data into (waiting) ______ elements. JUST TRY IT
Addressing elements by number is not the preferred way to extract XML elements. Using ______ is better. JUST TRY IT
![Page 9: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/9.jpg)
9
The HttpRequest Object The httpRequest object is not a part of the
W3C DOM __________. How to get an XML file from the server using
the httpRequest object (works only in IE): Try it Yourself or Try this example
How to get an XML file from the server using the httpRequest object (works only in IE): Try it Yourself
You can also send an XML document to an ASP page on the server, analyze the request, and send back the result. Try it Yourself (see the w3Schools page for ASP
code)
![Page 10: CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way](https://reader036.vdocuments.site/reader036/viewer/2022082611/56649e8e5503460f94b91207/html5/thumbnails/10.jpg)
10
DOM NodeTypes Nodes are separated into different types. The XML file used in the examples:
note_special.xml We traverse the file to get the nodeType of
the nodes: NodeType We traverse the file to get the nodeName of
the same nodes: NodeName We traverse the file to get the nodeValue of
the same nodes: NodeValue In IE5, you can also get the nodeType as a
string, with the .nodeTypeString property: NodeTypeString