Professional Documents
Culture Documents
XML Parser
• All major browsers have a built-in XML parser to access and
manipulate XML.
• Before an XML document can be accessed, it must be loaded
into an XML DOM object.
• All modern browsers have a built-in XML parser that can
convert text into an XML DOM object.
• Javascript-an object-oriented computer programming
language commonly used to create interactive effects within
web browsers.
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.
XML DOM and HTML DOM
• The XML DOM is a standard for how to
get, change, add, or delete XML elements.
It presents an XML document as a tree-
structure.
• The HTML DOM defines a standard way
for accessing and manipulating HTML
documents. It presents an HTML document
as a tree-structure.
DOM specification levels
• DOM Level 1 and Level 2 specifications
are W3C Recommendations.
• Level 1 allows navigation around an HTML
or XML document, and manipulation of the
content in that document.
• Level 2 extends Level 1 with a number of
features: XML Namespace support, filtered
views, ranges, events, etc.
DOM implementation and DOM
application
• A DOM implementation (also called a host
implementation) is that piece of software which takes
the parsed XML or HTML document and makes it
available for processing via the DOM interfaces. A
browser contains a hosting implementation
• A DOM application (also called a client application) is
that piece of software which takes the document made
available by the implementation, and does something
to it. A script which runs in a browser is an example
of an application.
What programming languages can I use
with the DOM?
• This will depend on what hosting implementation you
want to use it with.
• A browser might implement a JavaScript or VBScript
interface, so you can use those scripting languages
within the page itself to manipulate the page or change
the CSS style sheet.
• A editor might implement a Scheme or Java interface so
you can write an executable in those languages that talks
to your editor to manipulate the page.
• DOM is a set of interfaces; different companies will be
able to implement these interfaces in different ways. It is
unlikely that any one company will give you a choice of
C++ and Java and Scheme and Perl and Python and ...,
but interfaces in all these languages will be possible,
since the DOM itself is language-neutral.
JavaScript in IE 5.0
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");
VBScript
set xmlDoc = CreateObject("Microsoft.XMLDOM")
ASP
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
W3C DOM specification
• ProcessingInstruction
• Represents a processing instruction, which is used in XML
to provide specific information about the document to the
processor.
• Possible children: No children
The Node Interface
• XML parser can be used to load an XML
document into the memory of your computer
• 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
• 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
XML DOM Parser: language-neutral
programming model
text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
</script>
</body>
</html>
Example explained
• xmlDoc = parser.parseFromString(text,"text/xml");