jam*_*gan 1 c# xml vb.net asp.net
我将XML
输出存储到String
和再次将此字符串转换为XML.我成功将XML
输出转换为String,但我再次遇到问题将字符串转换为XML.
示例代码:
webservice.Service1 objService1 = new webservice.Service1();
String s = objService1.HelloWorld(); //Convert XML output into String
XmlDocument xd = new XmlDocument();
xd.LoadXML(s);
Run Code Online (Sandbox Code Playgroud)
我使用LoadXML()
方法,但我得到了错误
Data at the root level is invalid. Line 1 position 1.
Run Code Online (Sandbox Code Playgroud)
感谢,如果有任何正文提供正确的代码,在c#中将String转换为XML.谢谢,
你应该使用XDocument.XDocument比XMLDocument更好.它非常高效,简单且易于使用.
你的代码:
webservice.Service1 objService1 = new webservice.Service1();
String s = objService1.HelloWorld(); //Convert XML output into String
XmlDocument xd = new XmlDocument();
xd.LoadXml(s);
Run Code Online (Sandbox Code Playgroud)
解:
XDocument xd = XDocument.Parse(s);
Run Code Online (Sandbox Code Playgroud)