xmldocument类型末尾的错误[]

时间:2015-10-20 17:05:55

标签: .net f# plist xmldocument

您好我正在使用XmlDocument更新plist,当我保存它时看起来像<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" []>

打算<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

这是我的代码

UpdatePlist.fs:

namespace TestPlist

open System
open System.Xml


module UpdatePlist =
  type PlistLocation = PlistLocation of string
  type Version = Version of string

  let updatePlist ( PlistLocation(plist), Version(stable), Version(revision), Version(last) )  =
    let mydocument = new XmlDocument()
    mydocument.Load(plist)
    mydocument.PreserveWhitespace |> ignore
    let PlistNodes = mydocument.SelectNodes("descendant::key")
    let version = stable + "." + revision + "." + last
    PlistNodes.Item(8).NextSibling.InnerText <- version
    mydocument.Save(plist)
    "done"

和Program.fs:

 namespace TestPlist
 open UpdatePlist
 module Main=
   [<EntryPoint>]
   let main argv = 
       updatePlist(PlistLocation("../../Info.plist"), Version("8"), Version("5"), Version("9"))
       |> printfn "%A"

Plist文件Info.plist:

<?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>UIDeviceFamily</key>
   <array>
     <integer>1</integer>
     <integer>2</integer>
   </array>
   <key>CFBundleInfoDictionaryVersion</key>
   <string>6.0</string>
   <key>CFBundleExecutable</key>
   <string>
   </string>
   <key>UISupportedInterfaceOrientations</key>
   <array>
     <string>UIInterfaceOrientationPortrait</string>
   </array>
   <key>LSApplicationCategoryType</key>
   <string>
   </string>
   <key>MinimumOSVersion</key>
   <string>8</string>
   <key>CFBundleDisplayName</key>
   <string></string>
   <key>CFBundleIdentifier</key>
   <string></string>
   <key>CFBundleShortVersionString</key>
   <string>8.5.9</string>
   <key>CFBundleVersion</key>
   <string>1</string>
 </dict>
</plist>

请帮助!

1 个答案:

答案 0 :(得分:1)

我找到了答案

let documentTypeWithNullInternalSubset = mydocument.CreateDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
mydocument.ReplaceChild(documentTypeWithNullInternalSubset, mydocument.DocumentType) |> ignore

所有在save()

之前

我找到了这个帖子, C# LINQ TO XML - Remove "[]" characters from the DTD header 所以这个问题之前已经存在:/抱歉