Re: text to XML object (E4X)

hluz <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xml
Organization Another Netscape Collabra Server User
Message-ID <[email protected]>
Martin Honnen wrote:
> hluz wrote: 

>> 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, ''))
> 

Thanks for your reply Martin. Yes, removing it works fine. Just one 
question: Shouldn't the xml declaration be considered a Processing 
Instruction and as such be ingnored when property 
XML.ignoreProcessingInstructions = true?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.