有如下字符串:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/><soapenv:Body soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><p983:getPublicInterfaceResponse xmlns:p983="http://publicinterface.services.cbos2.nbport.com"><getPublicInterfaceReturn xsi:type="soapenc:Array" soapenc:arrayType="xsd:string[3,4]"><item xsi:type="xsd:string">OPERATE_TYPE</item> <item xsi:type="xsd:string">OPERATE_TYPE_NAME</item><item xsi:type="xsd:string">CUSTOMER_TYPE</item><item xsi:type="xsd:string">DOWNLOAD_TIMESTAMP</item><item xsi:type="xsd:string">1</item><item xsi:type="xsd:string">mothed1</item><item xsi:type="xsd:string">S</item><item xsi:type="xsd:string">20150720123952</item><item xsi:type="xsd:string">2</item><item xsi:type="xsd:string">mothed2</item><item xsi:type="xsd:string">S</item><item xsi:type="xsd:string">20150720123952</item></getPublicInterfaceReturn></p983:getPublicInterfaceResponse></soapenv:Body></soapenv:Envelope>
粗体部分是12个 <item xsi:type="xsd:string">xxxxx</item> 这样的结构数据,其中xxxxx是数据,我要一个正则表达式通过Regex获得12个<item xsi:type="xsd:string">xxxxx</item>里面的xxxx。
------解决思路----------------------
当工具箱里只有锤子的时候,所有的问题都是钉子:)
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
foreach(XmlNode node in doc.SelectNodes("//item"))
{
Console.WriteLine(node.InnerText);
}
------解决思路----------------------
string xml = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<soapenv:Header soapenv:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""/>
<soapenv:Body soapenv:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""><p983:getPublicInterfaceResponse xmlns:p983=""http://publicinterface.services.cbos2.nbport.com"">
<getPublicInterfaceReturn xsi:type=""soapenc:Array"" soapenc:arrayType=""xsd:string[3,4]""><item xsi:type=""xsd:string"">OPERATE_TYPE</item> <item xsi:type=""xsd:string"">OPERATE_TYPE_NAME</item><item xsi:type=""xsd:string"">CUSTOMER_TYPE</item><item xsi:type=""xsd:string"">DOWNLOAD_TIMESTAMP</item><item xsi:type=""xsd:string"">1</item><item xsi:type=""xsd:string"">mothed1</item><item xsi:type=""xsd:string"">S</item><item xsi:type=""xsd:string"">20150720123952</item><item xsi:type=""xsd:string"">2</item><item xsi:type=""xsd:string"">mothed2</item><item xsi:type=""xsd:string"">S</item><item xsi:type=""xsd:string"">20150720123952</item></getPublicInterfaceReturn></p983:getPublicInterfaceResponse></soapenv:Body>
</soapenv:Envelope>";
XElement root = XElement.Parse(xml);
XNamespace nameSpace = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace responseNameSpace = "http://publicinterface.services.cbos2.nbport.com";
var response = root.Element(nameSpace + "Body").Element(responseNameSpace + "getPublicInterfaceResponse");
var items = response.Element("getPublicInterfaceReturn").Elements("item");
string[,] resultArr = new string[3, 4];
int i = 0;
foreach (var item in items)
{
resultArr[i / 4, i % 4] = item.Value;
i++;
}
------解决思路----------------------
(?<=<item\x20+xsi\:type\=[^>]+>)[^<>]+