Solved

Error reading XML file

Posted on 2004-09-07
3
345 Views
Last Modified: 2010-05-18
I am trying to read and display the contents of an XML file. (I want to restructure the output too using Javascript but I can't get past this first hurdle)

This is the error:
=============================================
Response object error 'ASP 0185 : 80020003'

Missing Default Property

/displayxml.asp, line 30

A default property was not found for the object.
=============================================

Here is the Code:
=============================================
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<%
  var xmlDoc = new ActiveXObject("MSXML.DOMDocument");
  var sourceFile = Server.MapPath("xml_file.xml");  
 
  function loadXML(xmlFile)
  {
   xmlDoc.async="false";
   xmlDoc.onreadystatechange=verify;
   xmlDoc.loadXML(xmlFile);
   xmlObj=xmlDoc.documentElement;
  }

function verify()
{
 // 0 Object is not initialized
 // 1 Loading object is loading data
 // 2 Loaded object has loaded data
 // 3 Data from object can be worked with
 // 4 Object completely initialized
 if (xmlDoc.readyState != 4);
 {
   return false;
 }
}

loadXML(sourceFile);
Response.ContentType = "text/html";

Response.Write(xmlObj); //This is line 30
%>

I know that I should use Response.ContentType = "text/xml"; but I need to get past this ASP error first which is only displayed using text/html

Can anyone spot the problem ?
0
Comment
Question by:Milkybar-kid
  • 2
3 Comments
 
LVL 15

Expert Comment

by:Thogek
ID: 12002360
Try
    Response.Write(xmlObj.xml);
0
 
LVL 1

Author Comment

by:Milkybar-kid
ID: 12003998
I had already tried that. I get the message

Microsoft JScript runtime error '800a01a8'

Object required

/displayxml.asp, line 30
0
 
LVL 15

Accepted Solution

by:
Thogek earned 500 total points
ID: 12007751
Which suggests that xmlObj is not being correctly populated.  I'd suggest two things:

[1]
To be safe, you should declare xmlObj outside of the functions, just to ensure that xmlObj is a global (not method) variable.  Something like

    var xmlDoc = new ActiveXObject("MSXML.DOMDocument");
    var sourceFile = Server.MapPath("xml_file.xml");  
    var xmlObj = null;  // declared as global-scope variable

    function loadXML(xmlFile)
    {

[2]
The DOMDocument.loadXML expects to be passed a string containing XML-formatted data.  If you want to load the XML contained within a file whose pathname you will pass to the function, use the load method instead.  I.e.,

    function loadXML(xmlFile)
    {
        xmlDoc.async="false";
        xmlDoc.onreadystatechange=verify;
        xmlDoc.load(xmlFile);  // load XML from file
        xmlObj=xmlDoc.documentElement;
    }

DOMDocument.load: http://msdn.microsoft.com/library/en-us/xmlsdk/html/xmmthload.asp
DOMDocument.loadXML: http://msdn.microsoft.com/library/en-us/xmlsdk/html/xmmthloadxml.asp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now