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!

Can't read XML File in ASP

Status
Not open for further replies.

JuanitaC

Programmer
Feb 21, 2001
292
CA
I have an XML file called test.xml in the same folder as my test.asp. The ASP file can't read the xml file for some reason when I do this (I don't get an error, just nothing prints out like it does in the second example):
Code:
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
If Err<>0 then
	Response.Write(&quot;Object not created<br>&quot; & Err.Description & &quot;<br>&quot;)
end if
xmlDoc.async=&quot;false&quot;
xmlDoc.load(&quot;test.xml&quot;)

Response.Write(xmlDoc.text)

But if I do this it works fine:
Code:
text=&quot;<note>&quot;
text=text+&quot;<to>Tove</to><from>Jani</from>&quot;
text=text+&quot;<heading>Reminder</heading>&quot;
text=text+&quot;<body>Don't forget me this weekend!</body>&quot;
text=text+&quot;</note>&quot;

set xmlDoc = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)
If Err<>0 then
	Response.Write(&quot;Object not created<br>&quot; & Err.Description & &quot;<br>&quot;)
end if
xmlDoc.async=&quot;false&quot;
xmlDoc.loadxml(text)

Response.Write(xmlDoc.text)

I am new at this XML stuff, am I doing something wrong?

This is what my Test.xml file looks like:
<?xml version=&quot;1.0&quot;?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
 
Hello, JuanitaC,
There are two possible reasons why you can't get the results you want.
1) You are using for creating object - Microsoft.XMLDOM which is already old standard.
The new standard is Msxml2.DOMDocument
So the in the new way will be
set xmlDoc = Server.CreateObject(&quot;Msxml2.DOMDocument&quot;)
2) Your server cannot find the specified test.xml file.
Then you should use
xmlDoc.Load Server.MapPath(&quot;test.xml&quot;)
May be both lines have to be corrected in order to get your files working.
Good luck,
D.
 
Thanks... I just added the Server.MapPath and it works. But I will also add the updated standard for the DOM.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top