【发布时间】:2020-05-23 09:51:21
【问题描述】:
这里是xml
string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<UserMLogin xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://tempuri.org/\">
<Code>1</Code>
<Message>success</Message>
<Name>athil</Name>
</UserMLogin>";
我尝试了什么
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml.ToString());
XmlNodeList nodes = doc.DocumentElement.SelectNodes("/Code");
我得到了什么
<?xml version="1.0" encoding="utf-8"?><UserMLogin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/"> <Code>1</Code> <Message>success</Message> <Name>athil</Name></UserMLogin>
我期待什么
1
【问题讨论】:
-
您没有展示您是如何尝试读取这些值的,这使得帮助您变得更加困难。我建议尽管使用 LINQ to XML (XDocument),因为它使用 API 要简单得多。我建议从阅读docs.microsoft.com/en-us/dotnet/csharp/programming-guide/… 开始,然后尝试应用它,并编辑您的问题以显示您尝试过的内容以及您遇到的问题(如果您仍然卡住)。跨度>
标签: c# asp.net xml parsing soap