|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-02-16 10:06 UTC] misnet at hotmail dot com
Description: ------------ a.xml ============================================= <?xml version="1.0" encoding="GB2312"?> <Article> <Title>test</Title> <Author>ehero</Author> <ComeFrom>?ะน?</ComeFrom> <HtmlUrl>a.html</HtmlUrl> <CatalogId>2</CatalogId> <Contents><![CDATA[????]]></Contents> <AddTime>2005??</AddTime> <UpdateTime></UpdateTime> <Hits>3</Hits> <ServerFile></ServerFile> <LocalFile></LocalFile> <EncodeLocalFile></EncodeLocalFile> <PageIndex>0</PageIndex> <TotalPageNum>1</TotalPageNum> <PageUrl>a.shtml</PageUrl> </Article> ============================================= cms.xsl: ============================================= <?xml version="1.0" encoding="GB2312" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xsl:extension-element-prefixes="php"> <xsl:output method="html" encoding="GB2312" indent="yes"/> <xsl:template match="/"> <html> ..... ============================================= s.php: ============================================= <?php $xml = new DOMDocument("1.0","GB2312"); $xml->load("a.xml"); $xsl = new DOMDocument("1.0","GB2312"); $xsl->load("cms.xsl"); $proc = new XSLTProcessor; $proc->importStyleSheet($xsl); $proc->registerPHPFunctions(); $d = $proc->transformToUri($xml,"s.xml"); ?> ============================================= When I run s.php, it will be wrong!.Below is the exception messages. Warning: output conversion failed due to conv error in D:\myphp\yibo\t.php on line 9 Warning: Bytes: 0xB5 0xEB 0x2D 0x3C in D:\myphp\yibo\t.php on line 9 I have tested $xml->load("a.xml") and $xsl->load("cms.xsl"),they are right. I can get $xml->saveXML() and $xsl->saveXML(). PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
$doc = new DOMDocument('1.0','ISO-8859-1'); // we want a nice output $doc->formatOutput = true; $familias = $doc->appendChild(new DOMElement('familias')); while ($fam_datos = mysql_fetch_array($data)){ $familia = $familias->appendChild(new DOMElement('familia')); $familia->appendChild(new DOMElement('Apellidos', $fam_datos['Familia'])); $familia->appendChild(new DOMElement('Representante', $fam_datos['Apellidos'])); $familia->appendChild(new DOMElement('Nombre', $fam_datos['Nombres'])); $familia->appendChild(new DOMElement('Edad', $fam_datos['Edad'])); $familia->appendChild(new DOMElement('Salud', 'Sano')); } header('Content-Type: text/xml'); $documento = $doc->saveXML(); echo $documento; OUTPUT <b>Warning</b>: output conversion failed due to conv error in <b>c:\home\prueba\www\grid\xml.php</b>...Here's some example code that shows the problem: <? header("Content-Type: text/html; charset=iso-8859-1"); error_reporting(E_ALL); $domfather = new domDocument('1.0', 'iso-8859-1'); $node = $domfather->createElement("xxx", chr(200)); $domfather->appendChild($node); echo "<pre>"; echo htmlspecialchars($domfather->saveXML()); $nodelist = $domfather->getElementsByTagName("xxx"); $data = $nodelist->item(0)->nodeValue; echo $data; echo strlen($data); ?> Character code 200 is an e grave and is a valid iso-8859-1 character. The output from my server is below. When I retrieve the node's data back, it is as expected. But it's the saveXML() code that seems to have a problem. I suspect the problem is with the utf-8 -> iso-8859 conversion before output. Warning: DOMDocument::saveXML() [function.DOMDocument-saveXML]: output conversion failed due to conv error in /Library/Tenon/ WebServer/WebSites/realtyjuggler.com/subscription/test.php on line 23 Warning: DOMDocument::saveXML() [function.DOMDocument-saveXML]: Bytes: 0xC8 0x3C 0x2F 0x78 in /Library/Tenon/WebServer/WebSites/ realtyjuggler.com/subscription/test.php on line 23 <?xml version="1.0" encoding="iso-8859-1"?> <xxx>?1