xp-framework/xp-framework — Issue #73: inconsistent behaviour in handling of encoding declaration of XML
Author: ppetermann
Created: 2011-10-19 16:11:03+00:00
State: open

## Problems
* the usage of lower or uppercase as a string for the encoding attribute of xml is not consistent through the framework.
* xml.parser.XmlParser has a default overriding the encoding information in an XML string (rather than using the XML's string as a default and having a way to override when necessary

## Description:
in the XP Framework there are quite a few places where an
encoding is set to either ISO-8859-1 or iso-8859-1.
In most places this does not really make a difference,
but the behaviour is inconsistent, since you can end up having a different case
in the declaration of xml by simply writing a Tree to string, loading the xml from string and printing
it out as a string again.

$message= new XmlRpcRequestMessage();
$message->create('random_method');
$message->setData(array('foo' => 'bar', 'foo2' => 'bar2'));
$xml = $message->serializeData();
echo $xml; // the declaration at this stage contains encoding="iso-8859-1"

in this example the encoding of the message is set by xml.Tree's default $encoding = 'iso-8859-1';
now if i take the string that this puts out, and load it fromString to an XmlRpcRequestMessage,

$message2 = XmlRpcRequestMessage::fromString($xml);
$xml = $message2->serializeData();
echo $xml; // first line at this stage contains encoding="ISO-8859-1"

XmlRpcRequestMessage::fromString will use Tree's fromString method,
which performs `$tree->setEncoding($parser->getEncoding());`.
xml.parser.XmlParser by default uses the encoding set in constructor
(except its forced to null there, which in this process does not happen),
overriding the endcoding information set in the xml file
(this is a bit weird behaviour too).

This default is set to ISO-8859-1, which causes the difference in the string returned.