0
votes

how to change the 14th line as changed value, And then save it as .plist file! i am trying to use XmlElement and then save it, but the problem is after i save that file, the doctype line will be ,I mean the "[]" has been added at the end of doctype line which will cause issue when iPhone use this file.in c#, how to edit it in right way?

app.plist

i use below code to modify .plist file:

XmlDocument doc = new XmlDocument();
        string plistPath = "app.plist";
        doc.Load(plistPath);
     foreach (var node in doc.SelectNodes("//string"))
        {
            if (node is XmlElement)
            {
                var elem = (XmlElement)node;
                if (elem.InnerText == "software-package")
                {
                    var versionElement = elem.NextSibling.NextSibling as XmlElement;
                    if (versionElement != null)
                    {
                        versionElement.InnerText = "PCDownload Url";
                    }
                }
            }
        }
        doc.Save(plistPath);

and the DOCTYPE line will changed to:< !DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"[]> in .plist file.

1
do you mean objective-c? why are you using c# in an iOS environment?ton.yeung

1 Answers

1
votes

I think your issue has to do with the XmlDocument.Save() method. As you already know, XML and plist files are slightly different, but the Save() method is trying to apply XML properties to your plist when saving.

Here are some options:

1) Use regular expressions. Buffer the file contents into a byte[], make your changes using regular expressions, and then write that buffer to .plist.

2) Parse the document using the XML parser, but don't use the built in Save() method. This may still result in unwanted modifications in the plist file, but it's worth a shot.