将 .plist 文件解析为纯 XML C#
我正在尝试使用 c# 读取我的 Apple Safari 历史记录,该历史记录存储在 plist 文件中,但是我总是收到错误,并且我不确定正确的方法是什么。 我尝试执行的代码是这样的:
XmlDocument xmd = new XmlDocument();
xmd.LoadXml(@"C:\Users\Oran\AppData\Roaming\AppleComputer\Safari\History.plist");
并且我总是收到以下错误: “根级别的数据无效。第 1 行,位置 1。”
有谁知道这段代码有什么问题并推荐读取 plist 文件的最佳方法是什么?
I'm trying to read my Apple Safari history with c#, which is stored in a plist file, however I always get an error and I'm not sure what the correct way is to do it.
The code I tried to execute is this:
XmlDocument xmd = new XmlDocument();
xmd.LoadXml(@"C:\Users\Oran\AppData\Roaming\AppleComputer\Safari\History.plist");
and I always get the following error:"Data at the root level is invalid. Line 1, position 1."
Does anyone know whats wrong with this code and recommend what is the best way to read plist files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来Apple Safari的history.plist是二进制plist。我发现了一个很棒的项目:
https://github.com/animetrics/PlistCS
从自述文件中:
It looks like that Apple Safari history.plist is binary plist. I've found a great project:
https://github.com/animetrics/PlistCS
From the readme:
试试这个,一切都应该没问题;-)
您使用的那个从字符串而不是文件加载 xml 数据。
try this and everyhing should be fine ;-)
The one you have used loads the xml data from a string not from a file.
plist 不一定是 XML。有四种不同的序列化方法 - 旧式(用于 NeXT;不再使用)、XML、二进制和 JSON(10.7 中的新方法)。出于效率原因,Safari 的 History.plist 很可能是二进制的。
如果我没记错的话,Windows 版 Safari 确实在 Common Files\Apple Application Support 中附带了
plutil.exe
。您可以使用plutil -convert xml1 SOME_FILE.plist
来转换文件。A plist doesn't have to be XML. There are four different serialization methods — old-style (for NeXT; no longer used), XML, binary and JSON (new in 10.7). Safari's History.plist is most likely binary, for efficiency reasons.
If I'm not mistaken, Safari for Windows does ship with
plutil.exe
in Common Files\Apple Application Support. You can use that likeplutil -convert xml1 SOME_FILE.plist
to convert your file.问题出在第二行,显示
“XmlDocument.XmlResolver 属性”并弄清楚如何制作
XmlDocument 从 XML 中指定的 URI 下载、解析并使用 DTD。
The problem is with the second line, saying
"XmlDocument.XmlResolver Property" and figure out how to make the
XmlDocument download, parse and use the DTD from the URI specified in the XML.