Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion text to XML object (E4X)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Martin Honnen  
View profile  
 More options Nov 2 2005, 1:06 pm
Newsgroups: netscape.public.mozilla.xml
From: Martin Honnen <mahotr...@yahoo.de>
Date: Wed, 02 Nov 2005 19:06:54 +0100
Local: Wed, Nov 2 2005 1:06 pm
Subject: Re: text to XML object (E4X)

hluz wrote:
> I'm having a problem with creating a XML object from a document received
> via XMLHTTPRequest.
> The following code:

> var x = new XML(responseText)

> gives javascript error: xml is a reserved identifier.
> If I remove the <?xml version="1.0"?> line from responseText before
> using it, it works fine.

It is by design as the authors of the E4X specification wanted it, the
specification for
   new XML(string)
says to do the following (13.4.2):
   Let x = ToXML(string)
and ToXML(string) is specified as follows (10.3.1):
   Parse the concatenation of
   <parent xmlns=", defaultNamespace, ">", string, "</parent>"
So that way a conforming implementation has to parse e.g.
   <parent xmlns=""><?xml version="1.0"?><root /></parent>
and that is not well-formed and gives a parse error.
Thus if you want to parse a string with XML markup make sure you throw
the XML declaration away before passing the string to new XML().

A regular expression to match the XML declaration is e.g.
   var xmlDeclaration = /^<\?xml version[^>]+?>/;
so you could try removing it e.g.
   new XML(responseText.replace(xmlDeclaration, ''))

--

        Martin Honnen
        http://JavaScript.FAQTs.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google