Lubox
03-11-2005, 05:01 PM
Hi
I have created a function that creates an XML document using the DOM functions. This was the easiest way I have found to create XML documents. However, I ran into a problem with textnodes and characters from the Norwegian alphabet( Æ Ø Å <- which you probably dont see).
My code:
$xmldoc = new DOMDocument('1.0','iso-8859-1');
$root = $xmldoc->createElement('MYROOT');
$root = $xmldoc->appendChild($root);
$NewChild = $xmldoc->createElement("MYCHILD");
$NewChild = $root->appendChild($NewChild);
$NewChild->appendChild($xmldoc->createTextNode("BØ"));
return $xmldoc ->saveXML();
When I run this, I get:
Warning: output conversion failed due to conv error in my_xml.php on line 116
Warning: Bytes: 0xD8 0x20 0x52 0x75 in my_xml.php on line 116
And the XML-document is cut short there, meaning that after the B in my textnode the XML just stops and will cause an error if I display it in the browser (since no tags has been properply ended).
Any suggestions on how to solve this? I've tried to use no encoding in the "new DOMDocument", and that will help finish the XML doc, but the Norwegian character looks like some chinese sign. I've tried with utf-8 there, but my browser will complain about "an invalid character was found in text content".
Thanks
Lubox
I have created a function that creates an XML document using the DOM functions. This was the easiest way I have found to create XML documents. However, I ran into a problem with textnodes and characters from the Norwegian alphabet( Æ Ø Å <- which you probably dont see).
My code:
$xmldoc = new DOMDocument('1.0','iso-8859-1');
$root = $xmldoc->createElement('MYROOT');
$root = $xmldoc->appendChild($root);
$NewChild = $xmldoc->createElement("MYCHILD");
$NewChild = $root->appendChild($NewChild);
$NewChild->appendChild($xmldoc->createTextNode("BØ"));
return $xmldoc ->saveXML();
When I run this, I get:
Warning: output conversion failed due to conv error in my_xml.php on line 116
Warning: Bytes: 0xD8 0x20 0x52 0x75 in my_xml.php on line 116
And the XML-document is cut short there, meaning that after the B in my textnode the XML just stops and will cause an error if I display it in the browser (since no tags has been properply ended).
Any suggestions on how to solve this? I've tried to use no encoding in the "new DOMDocument", and that will help finish the XML doc, but the Norwegian character looks like some chinese sign. I've tried with utf-8 there, but my browser will complain about "an invalid character was found in text content".
Thanks
Lubox