[phpxmlrpc] Re: R: About xmldoc and ISO-8859-1...

Patrick Gelin patrick.gelin at rpn.ch
Wed Nov 24 07:52:07 PST 2004


Gaetano Giunta wrote:

> Sorry, I think you're posting on the wrong mailing list.
> This one is for discussing the xmlrpc protocol implementation, not general
> XML issues. Anyway, there are some tips below
> 
> bye
> Gaetano

ok but this tips are really fines for me!


>> -----Messaggio originale-----
>> Da: phpxmlrpc-bounces at lists.usefulinc.com
>> [mailto:phpxmlrpc-bounces at lists.usefulinc.com]Per conto di
>> Patrick Gelin
>> Inviato: mercoledì 24 novembre 2004 13:09
>> A: phpxmlrpc at usefulinc.com
>> Oggetto: [phpxmlrpc] About xmldoc and ISO-8859-1...
>> 
>> 
>> Hi,
>> 
>> I'm trying to make DRES project
>> (http://sourceforge.net/projects/dres/)
>> compliant with ISO-8859-1.  I'm not using mbstring into my
>> windows 2000
>> server, I know there is problem with Internet Explorer browser...
>> 
>> I saw DRES it use 'xmldoc' API  into the file xmlutil.php.
>> But this fonction
>> seems not to be in use at this time. By the way I can't find any
>> documentation about UTF-8, ISO-8859-1 and so about XMLDOM API.
>> 
>> What I saw it's when I save a formula with DRES, it register
>> a XML file, and
>> the content is:
>> 
>> <?xml version="1.0"?>
>> <requirement identifier="aaaaaaaa" name="&#xE0;&#xE0;&#xE0;&#xE0;"
>> priority="high" status="draft"><revision date="2004-11-19 13:14:45"
>> label=""><author id="gelinp">Patrick
>> Gelin</author><comment></comment></revision><description>&#x9A
>> 69;</descripti
>> on></requirement>
>> 
>> The name filed was originaly:
>> 
>> name='àààà'
>> 
>> I don't know if it's UTF-8 or ISO-8859-1 format.
>> 
> 
> Hard to tell: there is too little context information.
> 
> Where does this xml chunk come from? Is it generated by PHP, taken from a
> file, received from the web or what?

This xml comes from a PHP script, writing into a XML file and this is the
content of the XML file with an ASCII editor.

> Is this shown in a browser via HTTP? If so, since the charset is not
> specified in the <?xml ?> tag, the charset used has to be specified in the
> HTTP headers.Check out the HTTP headers received with your xml page
> (install e.g. Mozilla with the LiveHTTPHEADERS plugin or any equivalent
> http sniffer / proxy)
> 
> Note: a historical cause of problems is that by the xml spec the xml
> charset, where not specified, should be assumed to be UTF-8. But when
> sending XML over HTTP, HTTP rules apply, and the default charset depends
> on the mime-type used (unless the charset is explicitly defined in the
> content-type header or inside the xml chunk itself), and for text/xml it
> is ISO-8859-1.

Ok, so I would like to set a ISO-8859-1 header but the PHP XML API creating
a XML file doesn't let me to parameter this but only XML version (APIs are
xmldoc, domxml_new_xmldoc)... This is the PHP code creating the XML file:

// retrieves form's submitted data reconstructed into bound document
        function get_submit($document="", $errors="")
        {
                global $HTTP_POST_VARS;

                if ($document)
                        $doc = xmldoc($document);
                else
                        $doc = domxml_new_xmldoc("1.0");

//              $formdoc = xmldocfile($this->definition);
                $formdoc = xmldoc(load_file($this->definition));
                $formctx = xpath_new_context($formdoc);

                $result = xpath_eval($formctx, "//field[@binding and (@display = 'edit' or
not(@display)) and @control != 'label' and @control != 'readonly']");
                foreach ($result->nodeset as $node)
                {
                        $value = $HTTP_POST_VARS[$node->get_attribute("name")];
                        if ($node->get_attribute("required") == "true" && !$value)
                                $errors[] = $node->get_attribute("label")." field is required";
                        if ($node->get_attribute("pattern")
&& !ereg($node->get_attribute("pattern"), $value))
                                $errors[] = $node->get_attribute("label")." does not match pattern";
                        put_xpath($doc, $node->get_attribute("binding"), $value);
                }
                /*
                $root = $formdoc->root();
                foreach ($root->children() as $node)
                        if ($node->tagname == "field")
                                put_xpath($doc, $node->get_attribute("binding"),
$HTTP_POST_VARS[$node->get_attribute("name")]);
                */
                return $doc->dumpmem();
        }

I saw dumped could take no documented parameters to select other UTF
encoding. So I modified the last line:

                return $doc->dumpmem(0,"ISO-8859-1");

But...
1. The dumpem warmed...

Warning: dumpmem(): output conversion failed due to conv error in D
\Inetpub\wwwroot\dres\lib\xmlforms.php on line 112

Warning: dumpmem(): Bytes: 0xE0 0xE0 0xE0 0xE0 in D
\Inetpub\wwwroot\dres\lib\xmlforms.php on line 112

Warning: dumpmem(): xmlOutputBufferFlush: encoder error in D
\Inetpub\wwwroot\dres\lib\xmlforms.php on line 112

2. The file content was...

<?xml version="1.0" encoding="ISO-8859-1"?>
<requirement identifier="&#x820;&#x820;&#x820;&#x800;"
name="&#x820;&#x820;&#x820;&#x820;" priority="high"
status="draft"><revision date="2004-11-24 16:49:31" label=""><author
id="gelinp">Patrick
Gelin</author><comment></comment></revision><description>

3. It's relaod with Sablotron failed...

Warning: Sablotron error on line 2: XML parser error 3: no element found in
D:\Inetpub\wwwroot\dres\lib\lib_xslt_internal.php on line 7

What do you think of this? 



More information about the phpxmlrpc mailing list