Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Namespace and Data Typing

Status
Not open for further replies.

ssimon

Technical User
Jun 15, 2006
2
US
I am trying to learn XML from a "Teach yourself" book. Below I have ran into a problem that is making me pull my hair out and I do not have much left. I have a HTML doc that should pull data from a external xml file in the same directory, however all I keep getting is "The root node is null" (which in the code I presume goes back to the rootelement which is set to doc1 which in turn is loading the test.xml file). I am not sure if my problem lies in the HTML, XML or script.

Test.xml
Code:
<xml version="1.0"?>
<Book xmlns:dt="urn:schemas-microsoft-com:datatypes"> 
<Author dt:dt="string">Good Writer</Author>
<Title dt:dt="string">Good Book</Title>
<PriceHardBack dt:dt="number">12.95</PriceHardBack>
<PricePaperBack dt:dt="number">2.95</PricePaperBack>
<Rank dt:dt="int">32</Rank>
<Grade dt:dt="char">A</Grade>
<InStock dt:dt="boolean">0</InStock>
<PublicationDate dt:dt="date">2000-03-30</PublicationDate>
<PreciseMoment dt:dt="dateTime.tz">2000-03-30T12:18</PreciseMoment>
<OneSignedInteger dt:dt="dt=i1">12</OneSignedInteger>
<TwoSignedInteger dt:dt="dt=i2">-12</TwoSignedInteger>
<OneUnsignedInteger dt:dt="dt=ui1">12</OneUnsignedInteger>
<TwoUnsignedInteger dt:dt="dt=ui2">12</TwoUnsignedInteger>
<OneRealNumber dt:dt="r4">12345.67891</OneRealNumber>
</Book>

Test.html
Code:
<html>
<head>
<title>USING THE ARRAY PROPERITES OF THE NODELIST TO READ AN XML FILE</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
var RootElement1;
var nodecount;
var xmlDoc1=new ActiveXObject("microsoft.xmldom");
xmlDoc1.load("test.xml");
function StartUp()
{
if(xmlDoc1.readyState=="4")
{
StartLoading();
}
else
{
alert("Process could not start");
}
}
function StartLoading()
{
	var loopindex;
	RootElement1=xmlDoc1.documentElement;
	if(RootElement1==null)
	{
	alert("The root node is null");
	document.write("<B><BIG>The data of the XML file cannot be accessed.</BIG></B>");
	}
	else
	{
	nodecount=RootElement1.childNodes.length;
	for(loopindex=0;loopindex<nodecount;loopindex++)
	{
document.write(RootElement1.childNodes.item(loopindex).nodeName+": ");
document.write(RootElement1.childNodes.item(loopindex).text+"<br>");
document.write("The data type is " +RootElement1.childNodes.item(loopindex).dataType+"<br>");
str1="The value of the nodeTypedVaule property is ";
document.write("str1+RootElement1.childNodes.item(loopindex).nodeTypedValue+<br><br>");	
}
}
}
// -->
</script>
</head>
<BODY onLoad="StartUp()">
</BODY>
</html>
 
[1]
><xml version="1.0"?>
[tt]<[red]?[/red]xml version="1.0"?>[/tt]

[2] You must instruct non-validating parsing.
[tt]
var xmlDoc1=new ActiveXObject("microsoft.xmldom");
[blue]xmlDoc1.validateOnParse=false;[/blue]
xmlDoc1.load("test.xml");
[/tt]
 
Thank you so much. There is nothing I hate more than trying to learn from a book that has incorrect information in it. I have found several areas of the book where the verbage points to another file that is not listed or data is missing from the print. Enough of my ramblings - thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top