Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xml Reading problem] A text after "CData section" is not enough string. #29

Open
Ushio opened this issue Feb 1, 2018 · 1 comment
Open

Comments

@Ushio
Copy link

Ushio commented Feb 1, 2018

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 ?

@3breadt
Copy link

3breadt commented May 22, 2018

The method GetNodeTextContents could also be replaced by getting the value of the XmlNode.InnerText property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants