Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HOWTO: Parse error trapping

4 views
Skip to first unread message

Adrian Herscu

unread,
Sep 11, 2002, 9:27:16 AM9/11/02
to
Hi all,

Using IE, I can test parsing errors (during XHTTPRequest loading, for
example):

if( requestXML.parseError.errorCode < 0 )
throw "BAD XML";

How this works in Mozilla?

Thanx,
Adrian.

Heikki Toivonen

unread,
Sep 11, 2002, 2:00:58 PM9/11/02
to
Adrian Herscu wrote:
> Using IE, I can test parsing errors (during XHTTPRequest loading, for
> example):
>
> if( requestXML.parseError.errorCode < 0 )
> throw "BAD XML";
>
> How this works in Mozilla?

We don't have a parserError member on the document at the moment. If we
detect an XML parsing error, the error is reported in the actual
document. The root element is named "parsererror" and it is in the
namespace "http://www.mozilla.org/newlayout/xml/parsererror.xml". You
can access requestXML only after the document has completely loaded. So
once the document is loaded you can do something like:

// XXX If the data can start with element named parsererror we need to
// check the namespace on the root element as well.
if (xmlhttp.responseXML.documentElement.localName == "parsererror") {
throw "BAD XML";
}


--
Heikki Toivonen

Adrian Herscu

unread,
Sep 11, 2002, 4:55:32 PM9/11/02
to

No other error information available?
Also, I tried to use the 'getNamespaceID' method, didn't work
(.documentElement.namespaceID ---> void).

Christian Stocker

unread,
Sep 11, 2002, 4:35:26 PM9/11/02
to
In <3D7FADC4...@icqmail.com>, Adrian Herscu wrote:

> Heikki Toivonen wrote:
>> Adrian Herscu wrote:
>>
>>> Using IE, I can test parsing errors (during XHTTPRequest loading, for
>>> example):
>>>
>>> if( requestXML.parseError.errorCode < 0 )
>>> throw "BAD XML";
>>>
>>> How this works in Mozilla?
>>
>>
>> We don't have a parserError member on the document at the moment. If we
>> detect an XML parsing error, the error is reported in the actual
>> document. The root element is named "parsererror" and it is in the
>> namespace "http://www.mozilla.org/newlayout/xml/parsererror.xml". You
>> can access requestXML only after the document has completely loaded. So
>> once the document is loaded you can do something like:
>>
>> // XXX If the data can start with element named parsererror we need to
>> // check the namespace on the root element as well. if
>> (xmlhttp.responseXML.documentElement.localName == "parsererror") {
>> throw "BAD XML";
>> }
>> }
>> }
>>
> No other error information available?

Look at this parseerror xml-document, there's some more information in it
than just "parse error" :)

chregu


--
http://wishlist.chregu.tv - http://bitflux.ch
http://php-de-luxe.ch - http://bitfluxeditor.org

0 new messages