解决问题之,wp项目中使用MatchCollection正则表达式匹配出错
在最近,出现了这么一个问题
本人使用正则表达式代码,解析响应output,意图获得周边的CMCC热点
代码如下:
//output="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<root>\n <responseHeader>\n <sequence>1372835359954</sequence>\n <timestamp>2013-07-03 15:11:05</timestamp>\n <version>1.0.0</version>\n <returnCode>0</returnCode>\n <errorMessage>成功</errorMessage>\n </responseHeader>\n <responsePage>\n <hasNextPage>false</hasNextPage>\n <hasPreviousPage>false</hasPreviousPage>\n <lastPageNumber>1</lastPageNumber>\n <totalCount>19</totalCount>\n <thisPageFirstElementNumber>1</thisPageFirstElementNumber>\n <thisPageLastElementNumber>19</thisPageLastElementNumber>\n <nextPageNumber>2</nextPageNumber>\n <previousPageNumber>0</previousPageNumber>\n <pageSize>20</pageSize>\n <thisPageNumber>1</thisPageNumber>\n <firstResult>0</firstResult>\n </responsePage>\n <hotpointInfoList>\n <hotpointInfo>\n <name>南方基地</name>\n <nasid>238366</nasid>\n <address>大观路旁天河软件园高塘园区内</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3963</longitude>\n <latitude>23.1771</latitude>\n <coverageArea>南方基地1.1栋、1.2栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>105.75882807199615</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>龟背山</name>\n <nasid>353477</nasid>\n <address>位于天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <coverageArea>南方基地1.1栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>374.05018988753386</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>中国移动南方基地</name>\n <nasid>272146</nasid>\n <address>广州天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <isRecommend>0</isRecommend>\n <distance>374.05018988753386</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW01</name>\n <nasid>351214</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1781</latitude>\n <coverageArea>软件产业服务中心A3区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1510.190977102228</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW02</name>\n <nasid>351213</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1782</latitude>\n <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1511.041725631744</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>车管所</name>\n <nasid>353627</nasid>\n <address>广州市天河区岑村华观路1732号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3813</longitude>\n <latitude>23.1697</latitude>\n <coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1648.3095911436724</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南职院呼叫中心东区</name>\n <nasid>352009</nasid>\n <address>广州天河东圃大观中路492号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4115</longitude>\n <latitude>23.1706</latitude>\n <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1810.5506628804496</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>富域尚品居BSW02</name>\n <nasid>238640</nasid>\n <address>广州市黄埔区黄埔东路3689号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4075</longitude>\n <latitude>23.165</latitude>\n <coverageArea>A2座1-3F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1837.7807562784299</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职6宿</name>\n <nasid>350950</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍6</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职5宿</name>\n <nasid>350951</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍5</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职4宿</name>\n <nasid>350952</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍4</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职1宿</name>\n <nasid>350953</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>1宿6-8F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教宿</name>\n <nasid>350947</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3866</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1917.0689651951118</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教学楼</name>\n <nasid>350948</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1921.8129564597668</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院2SW02</name>\n <nasid>353825</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1929.3985939077031</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院1SW01</name>\n <nasid>353826</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1929.3985939077031</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南学院南区A学生宿舍新南一栋SW01</name>\n <nasid>352002</nasid>\n <address>广州市萝岗区大观中路与科学大道交界处</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4121</longitude>\n <latitude>23.168</latitude>\n <coverageArea>学生宿舍新南一栋5F-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1996.9030436473365</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南学院西区A</name>\n <nasid>352003</nasid>\n <address>广州萝岗区大观中路新泰商业街直入</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4121</longitude>\n <latitude>23.168</latitude>\n <coverageArea>东1栋宿舍1F-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1996.9030436473365</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南学院南区A学生公寓南二栋SW02</name>\n <nasid>352004</nasid>\n <address>广州市萝岗区大观中路与科学大道交界处</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4121</longitude>\n <latitude>23.168</latitude>\n <coverageArea>学生公寓南二栋、南一栋、南三栋4F-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1996.9030436473365</distance>\n </hotpointInfo>\n </hotpointInfoList>\n</root>";
//output = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<root>\n <responseHeader>\n <sequence>1372834735931</sequence>\n <timestamp>2013-07-03 15:02:37</timestamp>\n <version>1.0.0</version>\n <returnCode>0</returnCode>\n <errorMessage>成功</errorMessage>\n </responseHeader>\n <responsePage>\n <hasNextPage>false</hasNextPage>\n <hasPreviousPage>false</hasPreviousPage>\n <lastPageNumber>1</lastPageNumber>\n <totalCount>16</totalCount>\n <thisPageFirstElementNumber>1</thisPageFirstElementNumber>\n <thisPageLastElementNumber>16</thisPageLastElementNumber>\n <nextPageNumber>2</nextPageNumber>\n <previousPageNumber>0</previousPageNumber>\n <pageSize>20</pageSize>\n <thisPageNumber>1</thisPageNumber>\n <firstResult>0</firstResult>\n </responsePage>\n <hotpointInfoList>\n <hotpointInfo>\n <name>南方基地</name>\n <nasid>238366</nasid>\n <address>大观路旁天河软件园高塘园区内</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3963</longitude>\n <latitude>23.1771</latitude>\n <coverageArea>南方基地1.1栋、1.2栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>123.84223184290781</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>中国移动南方基地</name>\n <nasid>272146</nasid>\n <address>广州天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <isRecommend>0</isRecommend>\n <distance>390.0144674166032</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>龟背山</name>\n <nasid>353477</nasid>\n <address>位于天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <coverageArea>南方基地1.1栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>390.0144674166032</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW01</name>\n <nasid>351214</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1781</latitude>\n <coverageArea>软件产业服务中心A3区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1526.5646190952175</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW02</name>\n <nasid>351213</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1782</latitude>\n <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1527.3123339589258</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>车管所</name>\n <nasid>353627</nasid>\n <address>广州市天河区岑村华观路1732号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3813</longitude>\n <latitude>23.1697</latitude>\n <coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1639.8963551806467</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南职院呼叫中心东区</name>\n <nasid>352009</nasid>\n <address>广州天河东圃大观中路492号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4115</longitude>\n <latitude>23.1706</latitude>\n <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1831.5665734766765</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>富域尚品居BSW02</name>\n <nasid>238640</nasid>\n <address>广州市黄埔区黄埔东路3689号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4075</longitude>\n <latitude>23.165</latitude>\n <coverageArea>A2座1-3F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1859.005718853418</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职6宿</name>\n <nasid>350950</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍6</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职5宿</name>\n <nasid>350951</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍5</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职4宿</name>\n <nasid>350952</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍4</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职1宿</name>\n <nasid>350953</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>1宿6-8F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教宿</name>\n <nasid>350947</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3866</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1897.6626410004128</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教学楼</name>\n <nasid>350948</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1902.362099635232</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院2SW02</name>\n <nasid>353825</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1910.997494236302</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院1SW01</name>\n <nasid>353826</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1910.997494236302</distance>\n </hotpointInfo>\n </hotpointInfoList>\n</root>";
returnData = new List<Dictionary<String, String>>();
Match codeMatch = Regex.Match(output, "<root>.*?<returnCode>(.*?)</returnCode>.*?</root>", RegexOptions.Singleline);
if (codeMatch.Success)
{
int code = parseCode(codeMatch.Groups[1].Value);
if (code == 0)
{
Match toGetTotalPageMatch = Regex.Match(output, "<root>.*?<returnCode>(.*?)</returnCode>.*?<lastPageNumber>(.*?)</lastPageNumber>.*?</root>", RegexOptions.Singleline);
string totalPage = toGetTotalPageMatch.Groups[2].Value;
MatchCollection hotspotMatches = Regex.Matches(output, "<hotpointInfo>.*?<name>(?<name>.*?)</name>.*?<address>(?<address>.*?)</address>.*?<cityCode>(?<city>.*?)</cityCode>.*?<type>(?<hottype>.*?)</type>.*?<longitude>(?<longitude>.*?)</longitude>.*?<latitude>(?<latitude>.*?)</latitude>.*?(.*?<coverageArea>(?<coverarea>.*?)</coverageArea>)?.*?<distance>(?<distance>.*?)</distance>.*?</hotpointInfo>", RegexOptions.Singleline);
foreach (Match hotspotMatch in hotspotMatches)
{
Dictionary<String, String> dict = new Dictionary<string, string>();
double distanceDou = double.Parse(hotspotMatch.Groups["distance"].Value);
//make display 110 meter
//not 110.12232453242 meter
int distanceInt = (int)distanceDou;
dict.Add("name", hotspotMatch.Groups["name"].Value);
dict.Add("address", hotspotMatch.Groups["address"].Value);
string city = FromCityIdToName(hotspotMatch.Groups["city"].Value);
dict.Add("city", city);
dict.Add("hottype", hotspotMatch.Groups["hottype"].Value);
dict.Add("longitude", hotspotMatch.Groups["longitude"].Value);
dict.Add("latitude", hotspotMatch.Groups["latitude"].Value);
dict.Add("coverarea", hotspotMatch.Groups["coverarea"].Value);
dict.Add("distance", Convert.ToString(distanceInt));
dict.Add("total", totalPage);
((List<Dictionary<String, String>>)returnData).Add(dict);
}
result = PORTAL_RESULT.GET_HOTSPOT_SUCCESS;
error = PORTAL_ERROR.OK;
}
问题现象:
(output均在注释中)
1.当output为
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<root>\n <responseHeader>\n <sequence>1372834735931</sequence>\n <timestamp>2013-07-03 15:02:37</timestamp>\n <version>1.0.0</version>\n <returnCode>0</returnCode>\n <errorMessage>成功</errorMessage>\n
</responseHeader>\n <responsePage>\n <hasNextPage>false</hasNextPage>\n <hasPreviousPage>false</hasPreviousPage>\n <lastPageNumber>1</lastPageNumber>\n <totalCount>16</totalCount>\n <thisPageFirstElementNumber>1</thisPageFirstElementNumber>\n
<thisPageLastElementNumber>16</thisPageLastElementNumber>\n <nextPageNumber>2</nextPageNumber>\n <previousPageNumber>0</previousPageNumber>\n <pageSize>20</pageSize>\n <thisPageNumber>1</thisPageNumber>\n <firstResult>0</firstResult>\n </responsePage>\n
<hotpointInfoList>\n <hotpointInfo>\n <name>南方基地</name>\n <nasid>238366</nasid>\n <address>大观路旁天河软件园高塘园区内</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3963</longitude>\n
<latitude>23.1771</latitude>\n <coverageArea>南方基地1.1栋、1.2栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>123.84223184290781</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>中国移动南方基地</name>\n <nasid>272146</nasid>\n
<address>广州天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <isRecommend>0</isRecommend>\n <distance>390.0144674166032</distance>\n
</hotpointInfo>\n <hotpointInfo>\n <name>龟背山</name>\n <nasid>353477</nasid>\n <address>位于天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n
<latitude>23.1775</latitude>\n <coverageArea>南方基地1.1栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>390.0144674166032</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW01</name>\n <nasid>351214</nasid>\n
<address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1781</latitude>\n <coverageArea>软件产业服务中心A3区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n
<distance>1526.5646190952175</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW02</name>\n <nasid>351213</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n
<type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1782</latitude>\n <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1527.3123339589258</distance>\n </hotpointInfo>\n <hotpointInfo>\n
<name>车管所</name>\n <nasid>353627</nasid>\n <address>广州市天河区岑村华观路1732号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3813</longitude>\n <latitude>23.1697</latitude>\n
<coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1639.8963551806467</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南职院呼叫中心东区</name>\n <nasid>352009</nasid>\n <address>广州天河东圃大观中路492号</address>\n
<province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4115</longitude>\n <latitude>23.1706</latitude>\n <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea>\n <isRecommend>0</isRecommend>\n
<distance>1831.5665734766765</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>富域尚品居BSW02</name>\n <nasid>238640</nasid>\n <address>广州市黄埔区黄埔东路3689号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n
<type>99</type>\n <longitude>113.4075</longitude>\n <latitude>23.165</latitude>\n <coverageArea>A2座1-3F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1859.005718853418</distance>\n </hotpointInfo>\n <hotpointInfo>\n
<name>华文中职6宿</name>\n <nasid>350950</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n
<coverageArea>学生宿舍6</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职5宿</name>\n <nasid>350951</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n
<province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍5</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n
</hotpointInfo>\n <hotpointInfo>\n <name>华文中职4宿</name>\n <nasid>350952</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n
<latitude>23.1923</latitude>\n <coverageArea>学生宿舍4</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职1宿</name>\n <nasid>350953</nasid>\n
<address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>1宿6-8F</coverageArea>\n <isRecommend>0</isRecommend>\n
<distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教宿</name>\n <nasid>350947</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n
<longitude>113.3866</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1897.6626410004128</distance>\n </hotpointInfo>\n <hotpointInfo>\n
<name>华文中职教学楼</name>\n <nasid>350948</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1924</latitude>\n
<coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1902.362099635232</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院2SW02</name>\n <nasid>353825</nasid>\n
<address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n
<isRecommend>0</isRecommend>\n <distance>1910.997494236302</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院1SW01</name>\n <nasid>353826</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n
<cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1910.997494236302</distance>\n
</hotpointInfo>\n </hotpointInfoList>\n</root>"
2.当output为:
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<root>\n <responseHeader>\n <sequence>1372835359954</sequence>\n <timestamp>2013-07-03 15:11:05</timestamp>\n <version>1.0.0</version>\n <returnCode>0</returnCode>\n <errorMessage>成功</errorMessage>\n
</responseHeader>\n <responsePage>\n <hasNextPage>false</hasNextPage>\n <hasPreviousPage>false</hasPreviousPage>\n <lastPageNumber>1</lastPageNumber>\n <totalCount>19</totalCount>\n <thisPageFirstElementNumber>1</thisPageFirstElementNumber>\n
<thisPageLastElementNumber>19</thisPageLastElementNumber>\n <nextPageNumber>2</nextPageNumber>\n <previousPageNumber>0</previousPageNumber>\n <pageSize>20</pageSize>\n <thisPageNumber>1</thisPageNumber>\n <firstResult>0</firstResult>\n </responsePage>\n
<hotpointInfoList>\n <hotpointInfo>\n <name>南方基地</name>\n <nasid>238366</nasid>\n <address>大观路旁天河软件园高塘园区内</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3963</longitude>\n
<latitude>23.1771</latitude>\n <coverageArea>南方基地1.1栋、1.2栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>105.75882807199615</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>龟背山</name>\n <nasid>353477</nasid>\n
<address>位于天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <coverageArea>南方基地1.1栋</coverageArea>\n <isRecommend>0</isRecommend>\n
<distance>374.05018988753386</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>中国移动南方基地</name>\n <nasid>272146</nasid>\n <address>广州天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n
<longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <isRecommend>0</isRecommend>\n <distance>374.05018988753386</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW01</name>\n <nasid>351214</nasid>\n
<address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1781</latitude>\n <coverageArea>软件产业服务中心A3区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n
<distance>1510.190977102228</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW02</name>\n <nasid>351213</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n
<type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1782</latitude>\n <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1511.041725631744</distance>\n </hotpointInfo>\n <hotpointInfo>\n
<name>车管所</name>\n <nasid>353627</nasid>\n <address>广州市天河区岑村华观路1732号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3813</longitude>\n <latitude>23.1697</latitude>\n
<coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1648.3095911436724</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南职院呼叫中心东区</name>\n <nasid>352009</nasid>\n <address>广州天河东圃大观中路492号</address>\n
<province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4115</longitude>\n <latitude>23.1706</latitude>\n <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea>\n <isRecommend>0</isRecommend>\n
<distance>1810.5506628804496</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>富域尚品居BSW02</name>\n <nasid>238640</nasid>\n <address>广州市黄埔区黄埔东路3689号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n
<type>99</type>\n <longitude>113.4075</longitude>\n <latitude>23.165</latitude>\n <coverageArea>A2座1-3F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1837.7807562784299</distance>\n </hotpointInfo>\n <hotpointInfo>\n
<name>华文中职6宿</name>\n <nasid>350950</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n
<coverageArea>学生宿舍6</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职5宿</name>\n <nasid>350951</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n
<province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍5</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n
</hotpointInfo>\n <hotpointInfo>\n <name>华文中职4宿</name>\n <nasid>350952</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n
<latitude>23.1923</latitude>\n <coverageArea>学生宿舍4</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职1宿</name>\n <nasid>350953</nasid>\n
<address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>1宿6-8F</coverageArea>\n <isRecommend>0</isRecommend>\n
<distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教宿</name>\n <nasid>350947</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n
<type>99</type>\n <longitude>113.3866</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1917.0689651951118</distance>\n
</hotpointInfo>\n <hotpointInfo>\n <name>华文中职教学楼</name>\n <nasid>350948</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n
<latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1921.8129564597668</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院2SW02</name>\n
<nasid>353825</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n
<isRecommend>0</isRecommend>\n <distance>1929.3985939077031</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院1SW01</name>\n <nasid>353826</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n
<cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1929.3985939077031</distance>\n
</hotpointInfo>\n <hotpointInfo>\n <name>岭南学院南区A学生宿舍新南一栋SW01</name>\n <nasid>352002</nasid>\n <address>广州市萝岗区大观中路与科学大道交界处</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4121</longitude>\n
<latitude>23.168</latitude>\n <coverageArea>学生宿舍新南一栋5F-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1996.9030436473365</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南学院西区A</name>\n <nasid>352003</nasid>\n
<address>广州萝岗区大观中路新泰商业街直入</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4121</longitude>\n <latitude>23.168</latitude>\n <coverageArea>东1栋宿舍1F-6F</coverageArea>\n <isRecommend>0</isRecommend>\n
<distance>1996.9030436473365</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南学院南区A学生公寓南二栋SW02</name>\n <nasid>352004</nasid>\n <address>广州市萝岗区大观中路与科学大道交界处</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n
<type>99</type>\n <longitude>113.4121</longitude>\n <latitude>23.168</latitude>\n <coverageArea>学生公寓南二栋、南一栋、南三栋4F-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1996.9030436473365</distance>\n </hotpointInfo>\n </hotpointInfoList>\n</root>"
有龟背山热点,但是中国移动南方基地的距离有问题
表示很奇怪,问题应该出在
MatchCollection hotspotMatches = Regex.Matches(output, "<hotpointInfo>.*?<name>(?<name>.*?)</name>.*?<address>(?<address>.*?)</address>.*?<cityCode>(?<city>.*?)</cityCode>.*?<type>(?<hottype>.*?)</type>.*?<longitude>(?<longitude>.*?)</longitude>.*?<latitude>(?<latitude>.*?)</latitude>.*?(.*?<coverageArea>(?<coverarea>.*?)</coverageArea>)?.*?<distance>(?<distance>.*?)</distance>.*?</hotpointInfo>", RegexOptions.Singleline);
觉得代码没有错误,猜测:
wp项目中的正则表达式不够给力,(尤其是对于collection的处理)导致了这一问题的产生。
于是,尝试着不直接让MatchCollection一口吃成一个胖子
而是两步走,
- 获得具体的<hotpointInfo>...</hotpointInfo>节点
- 针对每一个node进行针对性的处理
心想,这样,总算是细嚼慢咽了吧
改进代码如下:
//output="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<root>\n <responseHeader>\n <sequence>1372835359954</sequence>\n <timestamp>2013-07-03 15:11:05</timestamp>\n <version>1.0.0</version>\n <returnCode>0</returnCode>\n <errorMessage>成功</errorMessage>\n </responseHeader>\n <responsePage>\n <hasNextPage>false</hasNextPage>\n <hasPreviousPage>false</hasPreviousPage>\n <lastPageNumber>1</lastPageNumber>\n <totalCount>19</totalCount>\n <thisPageFirstElementNumber>1</thisPageFirstElementNumber>\n <thisPageLastElementNumber>19</thisPageLastElementNumber>\n <nextPageNumber>2</nextPageNumber>\n <previousPageNumber>0</previousPageNumber>\n <pageSize>20</pageSize>\n <thisPageNumber>1</thisPageNumber>\n <firstResult>0</firstResult>\n </responsePage>\n <hotpointInfoList>\n <hotpointInfo>\n <name>南方基地</name>\n <nasid>238366</nasid>\n <address>大观路旁天河软件园高塘园区内</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3963</longitude>\n <latitude>23.1771</latitude>\n <coverageArea>南方基地1.1栋、1.2栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>105.75882807199615</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>龟背山</name>\n <nasid>353477</nasid>\n <address>位于天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <coverageArea>南方基地1.1栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>374.05018988753386</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>中国移动南方基地</name>\n <nasid>272146</nasid>\n <address>广州天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <isRecommend>0</isRecommend>\n <distance>374.05018988753386</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW01</name>\n <nasid>351214</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1781</latitude>\n <coverageArea>软件产业服务中心A3区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1510.190977102228</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW02</name>\n <nasid>351213</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1782</latitude>\n <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1511.041725631744</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>车管所</name>\n <nasid>353627</nasid>\n <address>广州市天河区岑村华观路1732号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3813</longitude>\n <latitude>23.1697</latitude>\n <coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1648.3095911436724</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南职院呼叫中心东区</name>\n <nasid>352009</nasid>\n <address>广州天河东圃大观中路492号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4115</longitude>\n <latitude>23.1706</latitude>\n <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1810.5506628804496</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>富域尚品居BSW02</name>\n <nasid>238640</nasid>\n <address>广州市黄埔区黄埔东路3689号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4075</longitude>\n <latitude>23.165</latitude>\n <coverageArea>A2座1-3F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1837.7807562784299</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职6宿</name>\n <nasid>350950</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍6</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职5宿</name>\n <nasid>350951</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍5</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职4宿</name>\n <nasid>350952</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍4</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职1宿</name>\n <nasid>350953</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>1宿6-8F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1911.9829741274648</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教宿</name>\n <nasid>350947</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3866</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1917.0689651951118</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教学楼</name>\n <nasid>350948</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1921.8129564597668</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院2SW02</name>\n <nasid>353825</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1929.3985939077031</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院1SW01</name>\n <nasid>353826</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1929.3985939077031</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南学院南区A学生宿舍新南一栋SW01</name>\n <nasid>352002</nasid>\n <address>广州市萝岗区大观中路与科学大道交界处</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4121</longitude>\n <latitude>23.168</latitude>\n <coverageArea>学生宿舍新南一栋5F-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1996.9030436473365</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南学院西区A</name>\n <nasid>352003</nasid>\n <address>广州萝岗区大观中路新泰商业街直入</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4121</longitude>\n <latitude>23.168</latitude>\n <coverageArea>东1栋宿舍1F-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1996.9030436473365</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南学院南区A学生公寓南二栋SW02</name>\n <nasid>352004</nasid>\n <address>广州市萝岗区大观中路与科学大道交界处</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4121</longitude>\n <latitude>23.168</latitude>\n <coverageArea>学生公寓南二栋、南一栋、南三栋4F-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1996.9030436473365</distance>\n </hotpointInfo>\n </hotpointInfoList>\n</root>";
//output = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<root>\n <responseHeader>\n <sequence>1372834735931</sequence>\n <timestamp>2013-07-03 15:02:37</timestamp>\n <version>1.0.0</version>\n <returnCode>0</returnCode>\n <errorMessage>成功</errorMessage>\n </responseHeader>\n <responsePage>\n <hasNextPage>false</hasNextPage>\n <hasPreviousPage>false</hasPreviousPage>\n <lastPageNumber>1</lastPageNumber>\n <totalCount>16</totalCount>\n <thisPageFirstElementNumber>1</thisPageFirstElementNumber>\n <thisPageLastElementNumber>16</thisPageLastElementNumber>\n <nextPageNumber>2</nextPageNumber>\n <previousPageNumber>0</previousPageNumber>\n <pageSize>20</pageSize>\n <thisPageNumber>1</thisPageNumber>\n <firstResult>0</firstResult>\n </responsePage>\n <hotpointInfoList>\n <hotpointInfo>\n <name>南方基地</name>\n <nasid>238366</nasid>\n <address>大观路旁天河软件园高塘园区内</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3963</longitude>\n <latitude>23.1771</latitude>\n <coverageArea>南方基地1.1栋、1.2栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>123.84223184290781</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>中国移动南方基地</name>\n <nasid>272146</nasid>\n <address>广州天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <isRecommend>0</isRecommend>\n <distance>390.0144674166032</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>龟背山</name>\n <nasid>353477</nasid>\n <address>位于天河软件园高唐新建区西部</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3989</longitude>\n <latitude>23.1775</latitude>\n <coverageArea>南方基地1.1栋</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>390.0144674166032</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW01</name>\n <nasid>351214</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1781</latitude>\n <coverageArea>软件产业服务中心A3区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1526.5646190952175</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>软件产业服务中心ASW02</name>\n <nasid>351213</nasid>\n <address>广州市天河区科学城高普路</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.41</longitude>\n <latitude>23.1782</latitude>\n <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1527.3123339589258</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>车管所</name>\n <nasid>353627</nasid>\n <address>广州市天河区岑村华观路1732号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3813</longitude>\n <latitude>23.1697</latitude>\n <coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1639.8963551806467</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>岭南职院呼叫中心东区</name>\n <nasid>352009</nasid>\n <address>广州天河东圃大观中路492号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4115</longitude>\n <latitude>23.1706</latitude>\n <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1831.5665734766765</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>富域尚品居BSW02</name>\n <nasid>238640</nasid>\n <address>广州市黄埔区黄埔东路3689号</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.4075</longitude>\n <latitude>23.165</latitude>\n <coverageArea>A2座1-3F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1859.005718853418</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职6宿</name>\n <nasid>350950</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍6</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职5宿</name>\n <nasid>350951</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍5</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职4宿</name>\n <nasid>350952</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>学生宿舍4</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职1宿</name>\n <nasid>350953</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1923</latitude>\n <coverageArea>1宿6-8F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1892.50686388558</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教宿</name>\n <nasid>350947</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3866</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1897.6626410004128</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>华文中职教学楼</name>\n <nasid>350948</nasid>\n <address>广州市天河区(G324)中大新华学院旁</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3865</longitude>\n <latitude>23.1924</latitude>\n <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1902.362099635232</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院2SW02</name>\n <nasid>353825</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1910.997494236302</distance>\n </hotpointInfo>\n <hotpointInfo>\n <name>新华学院1SW01</name>\n <nasid>353826</nasid>\n <address>广州市天河区凤凰街所辖的华美路口</address>\n <province>200</province>\n <cityCode>440100</cityCode>\n <type>99</type>\n <longitude>113.3882</longitude>\n <latitude>23.1932</latitude>\n <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>\n <isRecommend>0</isRecommend>\n <distance>1910.997494236302</distance>\n </hotpointInfo>\n </hotpointInfoList>\n</root>";
returnData = new List<Dictionary<String, String>>();
Match codeMatch = Regex.Match(output, "<root>.*?<returnCode>(.*?)</returnCode>.*?</root>", RegexOptions.Singleline);
if (codeMatch.Success)
{
int code = parseCode(codeMatch.Groups[1].Value);
if (code == 0)
{
Match toGetTotalPageMatch = Regex.Match(output, "<root>.*?<returnCode>(.*?)</returnCode>.*?<lastPageNumber>(.*?)</lastPageNumber>.*?</root>", RegexOptions.Singleline);
string totalPage = toGetTotalPageMatch.Groups[2].Value;
MatchCollection hotspotMatches = Regex.Matches(output, "<hotpointInfo>(.*?)</hotpointInfo>", RegexOptions.Singleline);
Regex hotspotRegex = new Regex("<hotpointInfo>.*?<name>(?<name>.*?)</name>.*?<address>(?<address>.*?)</address>.*?<cityCode>(?<city>.*?)</cityCode>.*?<type>(?<hottype>.*?)</type>.*?<longitude>(?<longitude>.*?)</longitude>.*?<latitude>(?<latitude>.*?)</latitude>.*?(.*?<coverageArea>(?<coverarea>.*?)</coverageArea>)?.*?<distance>(?<distance>.*?)</distance>.*?</hotpointInfo>", RegexOptions.Singleline);
foreach (Match hotspotNodeMatch in hotspotMatches)
{
Match hotspotMatch = hotspotRegex.Match(hotspotNodeMatch.Groups[0].Value);
if (hotspotMatch.Success)
{
Dictionary<String, String> dict = new Dictionary<string, string>();
double distanceDou = double.Parse(hotspotMatch.Groups["distance"].Value);
//make display 110 meter
//not 110.12232453242 meter
int distanceInt = (int)distanceDou;
dict.Add("name", hotspotMatch.Groups["name"].Value);
dict.Add("address", hotspotMatch.Groups["address"].Value);
string city = FromCityIdToName(hotspotMatch.Groups["city"].Value);
dict.Add("city", city);
dict.Add("hottype", hotspotMatch.Groups["hottype"].Value);
dict.Add("longitude", hotspotMatch.Groups["longitude"].Value);
dict.Add("latitude", hotspotMatch.Groups["latitude"].Value);
dict.Add("coverarea", hotspotMatch.Groups["coverarea"].Value);
dict.Add("distance", Convert.ToString(distanceInt));
dict.Add("total", totalPage);
((List<Dictionary<String, String>>)returnData).Add(dict);
}
}
实验发现,有效解决了问题,我称之为“龟背山问题”
总结经验,
不要盲目相信MatchCollection的能力,尤其针对复杂的正则表达式
将复杂的,大的问题拆分成小问题,相信计算机,对于处理针对化问题的能力,还是值得信赖的!
解决问题之,wp项目中使用MatchCollection正则表达式匹配出错的更多相关文章
- C#中,使用正则表达式匹配获取所需数据
.NET中,使用正则表达式匹配获取所需数据 需求:获取一串字符串中,正则匹配出需要的数据. 例如以下字符串: string temp ="ErrorCode:-1,Message:{&quo ...
- Python中使用中文正则表达式匹配指定的中文字符串
业务场景: 从中文字句中匹配出指定的中文子字符串 .这样的情况我在工作中遇到非常多, 特梳理总结如下. 难点: 处理GBK和utf8之类的字符编码, 同时正则匹配Pattern中包含汉字,要汉字正常发 ...
- 在项目中导入import javax.servlet 出错解决办法
我们有时会把别人的项目copy到自己这里进行二次开发或者参考学习,有的时候会发生下图的错误,即eclipse项目里我们导入的项目里提示HttpServletRequest 不能引用,会伴随头疼的小红叉 ...
- 在一串字符串中找到与正则表达式匹配的字符串?(例如:export_20170717_out.log 找到20170717)
如题:提取字符串:export_20170717_out.log 对应的日期: package dodo; import java.util.regex.Matcher; import java.ut ...
- 第11.18节 Python 中re模块的匹配对象
匹配对象是Python中re模块正则表达式匹配处理的返回结果,用于存放匹配的情况.老猿认为匹配对象更多的应该是与组匹配模式的功能对应的,只是没有使用组匹配模式的正则表达式整体作为组0. 为了说明下面的 ...
- C#正则表达式匹配HTML中的图片路径,图片地址
C#正则表达式匹配HTML中的图片路径,图片地址 最近的项目中有个关于网页取图的功能需要我自己开发,那就是用正则表达式来匹配图片标签. 一般来说一个 HTML 文档有很多标签,比如“< ...
- Java算法之递归打破及在真实项目中的使用实例
开心一笑 刚才领导问开发:"你觉得这个项目的最大风险是什么",开发说:"加班猝死" , 气氛尴尬了一分钟!!! 提出问题 1.递归算法简单复习 2.如何实现递归 ...
- 记一次ASP.NET MVC性能优化(实际项目中)
前言 在开发中为了紧赶项目进度而未去关注性能的问题,在项目逐渐稳定下来后发现性能令人感到有点忧伤,于是开始去关注这方面,本篇为记录在开发中遇到的问题并解决,不喜勿喷.注意:以下问题都是在移动端上出现, ...
- DotNet项目中的一些常用验证操作
在项目中需要对用户输入的信息,以及一些方法生成的结果进行验证,一般在项目中较多的采用js插件或js来进行有关信息的校验,但是从项目安全性的角度进行考虑,可对系统进行js注入. 如果在后台对用户输入的信 ...
随机推荐
- 时间类处理<1>
2016/05/31 14:47:21 [emerg] 14629#0: location "/nginx_status" is outside location "/p ...
- eclipsecdt添加自动补全功能
自动代码补全完全是一个改善生活质量的功能呀!cdt拥有自动代码补全功能,只是我们没有打开而已 1. 绑定快捷方式 1. windows -> preferences ->general-& ...
- qt model/view 架构自定义模型之QFileSystemModel
# -*- coding: utf-8 -*- # python:2.x #QFileSystemModel """ Qt 内置了两种模型:QStandardItemM ...
- html和css实现一级菜单和二级菜单学习笔记
实现一级菜单: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> ...
- [WebGL入门]十九,遮挡剔除和深度測试
注:文章译自http://wgld.org/,原作者杉本雅広(doxas),文章中假设有我的额外说明,我会加上[lufy:],另外.鄙人webgl研究还不够深入,一些专业词语,假设翻译有误.欢迎大家指 ...
- Highcharts属性
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- Linux中oracle的安装,亲测
一.下载oracle的软件包 地址: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-li ...
- JSP脚本元素上机手册
L3 <JSP基础>上机手册 内容回顾 脚本元素<%! %> <%= %> <% %> 注释元素 JSP指令元素 JSP动作元素 上机目标 掌握脚本元素 ...
- String()与toString()区别和应用
首先,String()和toString()方法都是将其它类型的变量转换为字符串的方法.但两者存在一定的区别: x.toString(): 无法转换null和undefined: 来看下面的小例子: ...
- 某Java游戏服务器用到的知识
Runtime.getRuntime().addShutdownHook(shutdownHook); shutdownHook()函数可以在jvm关闭的时候进行内存清理.对象销毁等操作 http:/ ...