Parsing XML Yourself

Let's say that you have this XML document, greeting.xml, which we developed earlier in this chapter:

<?xml version="1.0" encoding="UTF-8"?>
<DOCUMENT>
    <GREETING>
        Hello From XML
    </GREETING>
    <MESSAGE>
        Welcome to the wild and woolly world of XML.
    </MESSAGE>
</DOCUMENT>

Now say that you want to extract the greeting Hello From XML from this XML document. One way of doing that is by using XML data islands in Internet Explorer and then using a scripting language, such as JavaScript, to extract and display the text content of the <GREETING> element. Here's how that looks in a Web page:

 <HTML> <HEAD> <TITLE> Finding Element Values in an XML Document </TITLE> <XML ID="firstXML" SRC="greeting.xml"></XML> <SCRIPT LANGUAGE="JavaScript"> ...

Get Inside XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.