求一正则吧表达式

.Net技术 码拜 9年前 (2015-07-18) 1181次浏览 0个评论

有如下字符串:
<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。

#1

这个要什么正则啊,标准的xml啊……
50分

#2

回复1楼:

当工具箱里只有锤子的时候,所有的问题都是钉子:)

XmlDocument doc = new XmlDocument(); 
doc.LoadXml(xml);
foreach(XmlNode node in doc.SelectNodes("//item"))
{
    Console.WriteLine(node.InnerText);
}
20分

#3

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++;
}
30分

#4

(?<=<item\x20+xsi\:type\=[^>]+>)[^<>]+

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求一正则吧表达式
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!