Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 2nd, 2007, 10:21 AM
Authorized User
 
Join Date: Dec 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML That Is Not Well Formed

I've been working with AJAX for about a year now and something that I have not figured out yet is how to deal with xml that is not well formed. Typically, I will pass the xmlhttprequest object's responseXML to a function and if the passed xml is not well formed, a fatal error occurs and my script won't work. I have tried using try...catch to catch the error but that doesn't work. Can anyone shed some light how to test if the returned XML is well formed?
 
Old July 2nd, 2007, 11:14 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

In what circumstances would that happen?

--

Joe (Microsoft MVP - XML)
 
Old July 2nd, 2007, 11:38 AM
Authorized User
 
Join Date: Dec 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I generate most of the XML via PHP. When the PHP script fails either because of fatal errors, or whatever else is causing the problem, the returned XML is not valid.
 
Old July 2nd, 2007, 11:46 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well I think the PHP code should be changed to return an XML formatted error message if something goes wrong. Alternatively you will have to use the responseText property of the XmlHTTPRequest and first see if it's well-formed by trying to load it into an XML DOM. If it's not then use the text somehow. The first method seems easier and more resilient. If you are using SOAP style messages then this is what the SOAP fault was created for.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
The server tag is not well formed. binici ASP.NET 2.0 Basics 6 May 15th, 2007 04:41 PM
This file is not well-formed error crmpicco XML 1 April 25th, 2005 11:21 AM
how to output non-well formed string harag XSLT 5 November 10th, 2003 11:47 PM
Well formed HTML dkb XSLT 1 October 27th, 2003 01:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.