将包含xml的字符串加载到xmldocumet对象中并从中读取

将包含xml的字符串加载到xmldocumet对象中并从中读取

本文介绍了将包含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.

推荐答案

oXmlDocument.Load(a);



to:


to:

oXmlDocument.LoadXml(a);



[]用于从流,TextReader,路径/ URL或XmlReader加载XML。

[ ]是用于加载字符串变量中包含的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对象中并从中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 23:53