通过 XNA 中的 StreamReader 替换 XML 文件中的单词?
好吧,这有点像黑客攻击……但可能必须如此。我正在 XNA 中编写一个应用程序,根据我对这个问题的研究,它显然不支持 XML 版本 1.1。我正在阅读 ePub 文档的内容,其中一本较新的书籍将其内容编码为 1.1 版 XML 文档。这导致我的程序崩溃,但是结构与其余的相同。唯一阻止它工作的是 XmlDocument 类中的硬编码“1.0”。
我是否可以从流中读取文件,看看它是否包含:
并简单地将其替换为“1.0”?然后我可以将其作为 XmlDocument 拉入。我没有对文件进行任何写入,也没有进行任何复杂的结构读取,只是寻找一些特定的节点并提取值,所以我不知道这会产生什么后果。
Okay, so this is sort of a hack...but it may have to be. I'm writing an app in XNA, which from my research into this problem apparently doesn't support XML version 1.1. I'm reading in the contents of an ePub document, and one of the newer books encodes its content as a version 1.1 XML document. This causes my program to crash, however, the structure is the same as the rest. The only thing that is keeping it from working is the hard-coded "1.0" in the XmlDocument class.
Is it possible that I could read in the file from the stream, see if it contains:
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
and simply replace it with "1.0"? Then I could pull it in as an XmlDocument. I'm not doing any writing to the file, or any complex structural reading, just looking for a few specific nodes, and pulling in the values, so I don't know what the ramifications of this would be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过将整个 XML 文件读入内存并按照自己的方式使用它,以一种非常狡猾的方式完成此操作:
它适用于您提供的示例字符串,但我还没有在格式不完美的 XML 文档上测试它。
You can do this in a very dodgy way by reading the entire XML file into memory and having your way with it:
It works for the example string you provide, but I haven't tested it on imperfectly-formatted XML documents.