将包含xml的字符串加载到xmldocumet对象中并从中读取 [英] loading a xml containing string into a xmldocumet object and reading from it

查看:62
本文介绍了将包含xml的字符串加载到xmldocumet对象中并从中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string a = null;
a = getresponsefromserver(stringrequest);//This function returns the response xml
System.Xml.XmlDocument oXmlDocument = new System.Xml.XmlDocument();
oXmlDocument.Load(a); // here is the place where error occurs





这里的问题是,我在。

中获得了所需的响应但是当我尝试将其加载到xmldocument中时,它会显示非法字符。

我已确保响应xml的格式正确。



the problem here is, I am getting the desired response in a.
but when I try to load it into a xmldocument it show illegal characters found.
I have made sure that response xml is in right format.

推荐答案

更改您的代码行:

Change your line of code from:
oXmlDocument.Load(a);



to:


to:

oXmlDocument.LoadXml(a);



XmlDocument.Load() [ ^ ]用于从流,TextReader,路径/ URL或XmlReader加载XML。

XmlDocument.LoadXml() [ ^ ]是用于加载字符串变量中包含的XML



祝你好运,

OI


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 variable

Good luck,
OI


这篇关于将包含xml的字符串加载到xmldocumet对象中并从中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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