【问题标题】:Wrong [ ] at the end of xmldocument typexmldocument 类型末尾的 [ ] 错误
【发布时间】:2015-10-21 06:08:50
【问题描述】:

您好,我正在使用 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>

请帮忙!

【问题讨论】:

  • 请修复您的代码,然后也许我们可以提供帮助
  • 修复它,谢谢@Carsten
  • 我的猜测是,您的问题没有得到任何帮助,因为您无法让我们重现问题。请提供Short, Self Contained, Correct (Compilable), Example
  • 嗨@MarkSeemann,我已经更新了代码,并添加了一个plist文件

标签: .net f# plist xmldocument


【解决方案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 所以这个问题之前已经存在:/对不起

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多