plist-cil
plist-cil copied to clipboard
[Xml Reading problem] A text after "CData section" is not enough string.
Hi,
I trying following xml.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key><![CDATA[b%]]]]><![CDATA[>def]]></key>
<string><![CDATA[b%]]]]><![CDATA[>def]]></string>
</dict>
</plist>
I expected "b%]]>def" string and key. But I got "b%]]" It is strange.
Because, following CData parsing code is not enough. https://github.com/claunia/plist-cil/blob/master/plist-cil/XmlPropertyListParser.cs#L201
So, I propose following implementation.
static string GetNodeTextContents(XmlNode n)
{
if (n.NodeType == XmlNodeType.Text || n.NodeType == XmlNodeType.CDATA)
{
string content = n.Value; //This concatenates any adjacent text/cdata/entity nodes
return content ?? "";
}
if (n.HasChildNodes)
{
XmlNodeList children = n.ChildNodes;
string text = "";
foreach (XmlNode child in children)
{
//Skip any non-text nodes, like comments or entities
if (child.NodeType == XmlNodeType.Text || child.NodeType == XmlNodeType.CDATA)
{
if(child.Value != null) {
text += child.Value;
}
}
}
return text;
}
return "";
}
But it is hard for me to construct testing environment this project... :( How can I contribute ?
The method GetNodeTextContents
could also be replaced by getting the value of the XmlNode.InnerText
property.