Börni wrote:
- if the xml is created with server side scripting i need to do
something like this:
function createXMLFromString () {
var xmlParser, xmlDocument;
try {
xmlParser = new DOMParser();
xmlDocument = xmlParser.parseFromString(xmlhttp.responseText,
'text/xml');
No, I see no need to parse responseText, if the XML sent to the browser
has the proper Content-Type header and the encoding is properly declared
then responseXML should work. The browser doesn't really know or care
whether that XML sent to it stems from a static XML document the HTTP
server sends or from a PHP page run on the server.
Thus if you have any problems that the response from your PHP script is
not properly parsed by the browser then I would guess that there is
something wrong with your PHP trying to send XML.
PHP is byte oriented and mainly geared to create output in 8bit
encodings like ISO-8859-1 while XML parsers are not required to
understand such encodings with XML favouring Unicode and encodings such
as UTF-8 or UTF-16.
Thus if you want to output XML with a PHP page in an 8bit encoding you
might want to do it as follows:
<?php
$xmlString = '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n";
$xmlString .=
'<root><text xml:lang="de">Umlaute: ä, ö, ü</text></root>';
header('Content-Type: application/xml');
echo utf8_encode($xmlString);
?>
That way I have no problems here with the generated XML, whether I use
browsers like Mozilla, IE 6, Opera 8.00 beta to directly render the XML
sent from the PHP or whether I try to consume the XML with the
XMLHttpRequest object and access responseXML.
--
Martin Honnen
http://JavaScript.FAQTs.com/