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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display wrongly-formatted XML?

Status
Not open for further replies.

dcnguyen

Technical User
Mar 22, 2005
54
0
0
US
I've got an ajax call that reads a xml response as such:

var xmlDoc = request.responseXML;
var responseNode = xmlDoc.documentElement;
foo(responseNode);


What would I test to see if responseNode was properly formatted XML? Sometimes, the php script will echo an error that's not xml formatted...so I'd like this test to basically output anything that's not proper xml to an alert box.
 
You use the parseError method in javascript to find out if you have any problems with incoming XML.

The following is a snippet of code I made/copied that tests incoming XML:

Code:
  if(xmlDoc.parseError.errorCode!=0) {
     txt="Error Code: " + xmlDoc.parseError.errorCode + "\n";
     txt=txt+"Error Reason: " + xmlDoc.parseError.reason;
     txt=txt+"Error Line: " + objXML.parseError.line;
     alert(txt);
  }
  else {
     alert("No errors found");
  }


[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top