<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">m48333189002</string>
我如何从这个字符串之间访问值 m48333189002 ?
请帮忙
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">m48333189002</string>
我如何从这个字符串之间访问值 m48333189002 ?
请帮忙
您可以尝试解析 XML:
XElement.Parse(str).Value
可能最简单的方法是使用 string.Split 方法。
我想你期待如下,
进口:
using System.Xml;
using System.Xml.Linq;
代码 :
string xmlResult = "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">m48333189002</string>";
// place the sample result into a stream
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] xmlBytes = encoding.GetBytes(xmlResult);
// create a stream from the byte array
MemoryStream ms = new MemoryStream(xmlBytes);
// read and deserialize the xml
XmlTextReader respXmlRdr = new XmlTextReader(ms);
// Linq to XML to extract return value from namespace decorated
// return XML string
XDocument xDoc = XDocument.Load(respXmlRdr);
string Result = xDoc.Root.Value;
Console.WriteLine(Result);