XMLDocument.load方法VS XmlDocument.LoadXml [英] XmlDocument.Load Vs XmlDocument.LoadXml

查看:285
本文介绍了XMLDocument.load方法VS XmlDocument.LoadXml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是用 XmlDocument.LoadXml 遇到了一个问题。

I just came across with a problem using XmlDocument.LoadXml.

应用程序崩溃了,给以下错误:

The application was crashing, giving the following error:

的数据在根级别无效1号线,位置1

"Data at the root level is invalid. Line 1, position 1"

检查XML和发现不妥的地方后,我用Google搜索了一下,发现一个提示使用 XMLDocument.load方法而不是 XmlDocument.LoadXml

After inspecting the XML and finding nothing wrong with it, I googled a bit and found a tip to use XmlDocument.Load instead of XmlDocument.LoadXml.

我已经尝试过了,它完美的作品。

I have tried it and it works perfectly.

我的问题是:什么是2种方法,什么之间的差异可能有导致人们工作和其他失败?

My question is: What is the difference between the 2 methods and what could have cause one to work and the other to fail?

推荐答案

XMLDocument.load方法是用来加载XML无论是从流,TextReader的,路径/ URL,或XmlReader中。
XmlDocument.LoadXml 的用于加载包含在XML一个串内

XmlDocument.Load is used to load XML either from a stream, TextReader, path/URL, or XmlReader. XmlDocument.LoadXml is used to load the XML contained within a string.

它们加载的XML根本不同的方式,这取决于在XML实际存储在哪里。因此,它听起来就像你使用为你的XML是错误的方法。

They're fundamentally different ways of loading XML, depending on where the XML is actually stored. So it sounds like you were using the wrong method for where your XML is.

这篇关于XMLDocument.load方法VS XmlDocument.LoadXml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆