XML translation by IE? (Inside XML book example)

J

jeffc

I'm just learning XML and am reading "Inside XML" by Holzner. He gives an
early XML example file.
<?xml version = "1.0" encoding="UTF-8"?>

<DOCUMENT>

<GREETING>

Hello From XML

</GREETING>

<MESSAGE>

Welcome to the wild and wolly world of XML.

</MESSAGE>

</DOCUMENT>



He explains that when opened with IE, it will simply display the contents
(which it does.) Then he gives a second example, which he says will read
from that file when a button is pressed. The following code is supposed to
"execute" when opened with IE. But, all it does is display the formatted
text, just like the first example. Anyone know what's going on? (By the
way, I altered one of the lines. The tag "INPUT" was not valid, so I put a
"/" at the end of that tag. I'm assuming this was a typo in the book,
right?)



<HTML>

<HEAD>

<TITLE>

Finding Element Values in an XML Document

</TITLE>

<XML ID="firstXML" SRC="greeting.xml"> </XML>

<SCRIPT LANGUAGE="JavaScript">

function getData()

{

xmldoc = document.all("firstXML").XMLDocument;

nodeDoc = xmldoc.documentElement;

nodeGreeting = nodeDoc.firstChild;

outputMessage = "Greeting: " + nodeGreeting.firstChild.nodeValue;

message.innerHTML = outputMessage;

}

</SCRIPT>

</HEAD>

<BODY>

<CENTER>

<H1>

Finding Element Values in an XML Document

</H1>

<DIV ID="message"> </DIV>

<INPUT TYPE="BUTTON" VALUE="Get The Greeting" ONCLICK="getData()"/>

</CENTER>

</BODY>

</HTML>
 
M

Martin Honnen

jeffc said:
I'm just learning XML and am reading "Inside XML" by Holzner. He gives an
early XML example file.
<?xml version = "1.0" encoding="UTF-8"?>

<DOCUMENT>

<GREETING>

Hello From XML

</GREETING>

<MESSAGE>

Welcome to the wild and wolly world of XML.

</MESSAGE>

</DOCUMENT>



He explains that when opened with IE, it will simply display the contents
(which it does.) Then he gives a second example, which he says will read
from that file when a button is pressed. The following code is supposed to
"execute" when opened with IE. But, all it does is display the formatted
text, just like the first example. Anyone know what's going on? (By the
way, I altered one of the lines. The tag "INPUT" was not valid, so I put a
"/" at the end of that tag. I'm assuming this was a typo in the book,
right?)

What you have below is a HTML document and with HTML <INPUT> is proper
markup for an empty element, no need for any /> in HTML.

<HTML>

<HEAD>

<TITLE>

Finding Element Values in an XML Document

</TITLE>

<XML ID="firstXML" SRC="greeting.xml"> </XML>

<SCRIPT LANGUAGE="JavaScript">

function getData()

{

xmldoc = document.all("firstXML").XMLDocument;

nodeDoc = xmldoc.documentElement;

nodeGreeting = nodeDoc.firstChild;

outputMessage = "Greeting: " + nodeGreeting.firstChild.nodeValue;

message.innerHTML = outputMessage;

}

</SCRIPT>

</HEAD>

<BODY>

<CENTER>

<H1>

Finding Element Values in an XML Document

</H1>

<DIV ID="message"> </DIV>

<INPUT TYPE="BUTTON" VALUE="Get The Greeting" ONCLICK="getData()"/>

</CENTER>

</BODY>

</HTML>

After IE has loaded that HTML document you need to press the button "Get
the Greeting" so that IE (if scripting is enabled) executes the script
function getData. All that function does is reading out the text content
of the <GREETING> element in the XML document and display it above the
button in the HTML file.
 
J

jeffc

What you have below is a HTML document and with HTML <INPUT> is proper
markup for an empty element, no need for any /> in HTML.

I see my mistake now. I absent-mindedly saved the document as .XML rather
than .HTML, because that's how I saved the previous document. When I change
the type to .HTML all works well, even without the ending "/" for the INPUT
tag. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top