字符串转换为使用的.Net XML [英] Convert string to XML using .Net
本文介绍了字符串转换为使用的.Net XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我保存 XML
输出到字符串
并再次转换这个字符串到XML。我成功地转换 XML
输出字符串,但我有问题再次转换字符串XML。
I store the XML
output to String
and Again convert this string to XML .I successfully convert XML
output to String, but i got problem again converting string to XML.
的样品code:的
webservice.Service1 objService1 = new webservice.Service1();
String s = objService1.HelloWorld(); //Convert XML output into String
XmlDocument xd = new XmlDocument();
xd.LoadXML(s);
我用的loadXML()
的方法,但我得到了错误
I use LoadXML()
method, but i got error
Data at the root level is invalid. Line 1 position 1.
它的感激,如果任何机构给予正确的code到字符串转换为XML在C#。
谢谢
Its grateful, if any body give right code to convert String To XML in c#. Thank you,
推荐答案
您应该使用的XDocument 。 的XDocument 好过的XMLDocument 。这是非常有效的,简单易用。
You should use XDocument. XDocument is better than XMLDocument. It is very efficient, simple and easy to use.
您code:
webservice.Service1 objService1 = new webservice.Service1();
String s = objService1.HelloWorld(); //Convert XML output into String
XmlDocument xd = new XmlDocument();
xd.LoadXml(s);
解决方案:
XDocument xd = XDocument.Parse(s);
这篇关于字符串转换为使用的.Net XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文