在最近,出现了这么一个问题
本人使用正则表达式代码,解析响应output,意图获得周边的CMCC热点
代码如下:
//output="<?xml version="1.0" encoding="UTF-8" ?> <root> <responseHeader> <sequence>1372835359954</sequence> <timestamp>2013-07-03 15:11:05</timestamp> <version>1.0.0</version> <returnCode>0</returnCode> <errorMessage>成功</errorMessage> </responseHeader> <responsePage> <hasNextPage>false</hasNextPage> <hasPreviousPage>false</hasPreviousPage> <lastPageNumber>1</lastPageNumber> <totalCount>19</totalCount> <thisPageFirstElementNumber>1</thisPageFirstElementNumber> <thisPageLastElementNumber>19</thisPageLastElementNumber> <nextPageNumber>2</nextPageNumber> <previousPageNumber>0</previousPageNumber> <pageSize>20</pageSize> <thisPageNumber>1</thisPageNumber> <firstResult>0</firstResult> </responsePage> <hotpointInfoList> <hotpointInfo> <name>南方基地</name> <nasid>238366</nasid> <address>大观路旁天河软件园高塘园区内</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3963</longitude> <latitude>23.1771</latitude> <coverageArea>南方基地1.1栋、1.2栋</coverageArea> <isRecommend>0</isRecommend> <distance>105.75882807199615</distance> </hotpointInfo> <hotpointInfo> <name>龟背山</name> <nasid>353477</nasid> <address>位于天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <coverageArea>南方基地1.1栋</coverageArea> <isRecommend>0</isRecommend> <distance>374.05018988753386</distance> </hotpointInfo> <hotpointInfo> <name>中国移动南方基地</name> <nasid>272146</nasid> <address>广州天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <isRecommend>0</isRecommend> <distance>374.05018988753386</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW01</name> <nasid>351214</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1781</latitude> <coverageArea>软件产业服务中心A3区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1510.190977102228</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW02</name> <nasid>351213</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1782</latitude> <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1511.041725631744</distance> </hotpointInfo> <hotpointInfo> <name>车管所</name> <nasid>353627</nasid> <address>广州市天河区岑村华观路1732号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3813</longitude> <latitude>23.1697</latitude> <coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea> <isRecommend>0</isRecommend> <distance>1648.3095911436724</distance> </hotpointInfo> <hotpointInfo> <name>岭南职院呼叫中心东区</name> <nasid>352009</nasid> <address>广州天河东圃大观中路492号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4115</longitude> <latitude>23.1706</latitude> <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea> <isRecommend>0</isRecommend> <distance>1810.5506628804496</distance> </hotpointInfo> <hotpointInfo> <name>富域尚品居BSW02</name> <nasid>238640</nasid> <address>广州市黄埔区黄埔东路3689号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4075</longitude> <latitude>23.165</latitude> <coverageArea>A2座1-3F</coverageArea> <isRecommend>0</isRecommend> <distance>1837.7807562784299</distance> </hotpointInfo> <hotpointInfo> <name>华文中职6宿</name> <nasid>350950</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍6</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职5宿</name> <nasid>350951</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍5</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职4宿</name> <nasid>350952</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍4</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职1宿</name> <nasid>350953</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>1宿6-8F</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教宿</name> <nasid>350947</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3866</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1917.0689651951118</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教学楼</name> <nasid>350948</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1921.8129564597668</distance> </hotpointInfo> <hotpointInfo> <name>新华学院2SW02</name> <nasid>353825</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1929.3985939077031</distance> </hotpointInfo> <hotpointInfo> <name>新华学院1SW01</name> <nasid>353826</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1929.3985939077031</distance> </hotpointInfo> <hotpointInfo> <name>岭南学院南区A学生宿舍新南一栋SW01</name> <nasid>352002</nasid> <address>广州市萝岗区大观中路与科学大道交界处</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4121</longitude> <latitude>23.168</latitude> <coverageArea>学生宿舍新南一栋5F-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1996.9030436473365</distance> </hotpointInfo> <hotpointInfo> <name>岭南学院西区A</name> <nasid>352003</nasid> <address>广州萝岗区大观中路新泰商业街直入</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4121</longitude> <latitude>23.168</latitude> <coverageArea>东1栋宿舍1F-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1996.9030436473365</distance> </hotpointInfo> <hotpointInfo> <name>岭南学院南区A学生公寓南二栋SW02</name> <nasid>352004</nasid> <address>广州市萝岗区大观中路与科学大道交界处</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4121</longitude> <latitude>23.168</latitude> <coverageArea>学生公寓南二栋、南一栋、南三栋4F-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1996.9030436473365</distance> </hotpointInfo> </hotpointInfoList> </root>"; //output = "<?xml version="1.0" encoding="UTF-8" ?> <root> <responseHeader> <sequence>1372834735931</sequence> <timestamp>2013-07-03 15:02:37</timestamp> <version>1.0.0</version> <returnCode>0</returnCode> <errorMessage>成功</errorMessage> </responseHeader> <responsePage> <hasNextPage>false</hasNextPage> <hasPreviousPage>false</hasPreviousPage> <lastPageNumber>1</lastPageNumber> <totalCount>16</totalCount> <thisPageFirstElementNumber>1</thisPageFirstElementNumber> <thisPageLastElementNumber>16</thisPageLastElementNumber> <nextPageNumber>2</nextPageNumber> <previousPageNumber>0</previousPageNumber> <pageSize>20</pageSize> <thisPageNumber>1</thisPageNumber> <firstResult>0</firstResult> </responsePage> <hotpointInfoList> <hotpointInfo> <name>南方基地</name> <nasid>238366</nasid> <address>大观路旁天河软件园高塘园区内</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3963</longitude> <latitude>23.1771</latitude> <coverageArea>南方基地1.1栋、1.2栋</coverageArea> <isRecommend>0</isRecommend> <distance>123.84223184290781</distance> </hotpointInfo> <hotpointInfo> <name>中国移动南方基地</name> <nasid>272146</nasid> <address>广州天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <isRecommend>0</isRecommend> <distance>390.0144674166032</distance> </hotpointInfo> <hotpointInfo> <name>龟背山</name> <nasid>353477</nasid> <address>位于天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <coverageArea>南方基地1.1栋</coverageArea> <isRecommend>0</isRecommend> <distance>390.0144674166032</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW01</name> <nasid>351214</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1781</latitude> <coverageArea>软件产业服务中心A3区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1526.5646190952175</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW02</name> <nasid>351213</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1782</latitude> <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1527.3123339589258</distance> </hotpointInfo> <hotpointInfo> <name>车管所</name> <nasid>353627</nasid> <address>广州市天河区岑村华观路1732号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3813</longitude> <latitude>23.1697</latitude> <coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea> <isRecommend>0</isRecommend> <distance>1639.8963551806467</distance> </hotpointInfo> <hotpointInfo> <name>岭南职院呼叫中心东区</name> <nasid>352009</nasid> <address>广州天河东圃大观中路492号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4115</longitude> <latitude>23.1706</latitude> <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea> <isRecommend>0</isRecommend> <distance>1831.5665734766765</distance> </hotpointInfo> <hotpointInfo> <name>富域尚品居BSW02</name> <nasid>238640</nasid> <address>广州市黄埔区黄埔东路3689号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4075</longitude> <latitude>23.165</latitude> <coverageArea>A2座1-3F</coverageArea> <isRecommend>0</isRecommend> <distance>1859.005718853418</distance> </hotpointInfo> <hotpointInfo> <name>华文中职6宿</name> <nasid>350950</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍6</coverageArea> <isRecommend>0</isRecommend> <distance>1892.50686388558</distance> </hotpointInfo> <hotpointInfo> <name>华文中职5宿</name> <nasid>350951</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍5</coverageArea> <isRecommend>0</isRecommend> <distance>1892.50686388558</distance> </hotpointInfo> <hotpointInfo> <name>华文中职4宿</name> <nasid>350952</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍4</coverageArea> <isRecommend>0</isRecommend> <distance>1892.50686388558</distance> </hotpointInfo> <hotpointInfo> <name>华文中职1宿</name> <nasid>350953</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>1宿6-8F</coverageArea> <isRecommend>0</isRecommend> <distance>1892.50686388558</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教宿</name> <nasid>350947</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3866</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1897.6626410004128</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教学楼</name> <nasid>350948</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1902.362099635232</distance> </hotpointInfo> <hotpointInfo> <name>新华学院2SW02</name> <nasid>353825</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1910.997494236302</distance> </hotpointInfo> <hotpointInfo> <name>新华学院1SW01</name> <nasid>353826</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1910.997494236302</distance> </hotpointInfo> </hotpointInfoList> </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" ?>
<root>
<responseHeader>
<sequence>1372834735931</sequence>
<timestamp>2013-07-03 15:02:37</timestamp>
<version>1.0.0</version>
<returnCode>0</returnCode>
<errorMessage>成功</errorMessage>
</responseHeader>
<responsePage>
<hasNextPage>false</hasNextPage>
<hasPreviousPage>false</hasPreviousPage>
<lastPageNumber>1</lastPageNumber>
<totalCount>16</totalCount>
<thisPageFirstElementNumber>1</thisPageFirstElementNumber>
<thisPageLastElementNumber>16</thisPageLastElementNumber>
<nextPageNumber>2</nextPageNumber>
<previousPageNumber>0</previousPageNumber>
<pageSize>20</pageSize>
<thisPageNumber>1</thisPageNumber>
<firstResult>0</firstResult>
</responsePage>
<hotpointInfoList>
<hotpointInfo>
<name>南方基地</name>
<nasid>238366</nasid>
<address>大观路旁天河软件园高塘园区内</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3963</longitude>
<latitude>23.1771</latitude>
<coverageArea>南方基地1.1栋、1.2栋</coverageArea>
<isRecommend>0</isRecommend>
<distance>123.84223184290781</distance>
</hotpointInfo>
<hotpointInfo>
<name>中国移动南方基地</name>
<nasid>272146</nasid>
<address>广州天河软件园高唐新建区西部</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3989</longitude>
<latitude>23.1775</latitude>
<isRecommend>0</isRecommend>
<distance>390.0144674166032</distance>
</hotpointInfo>
<hotpointInfo>
<name>龟背山</name>
<nasid>353477</nasid>
<address>位于天河软件园高唐新建区西部</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3989</longitude>
<latitude>23.1775</latitude>
<coverageArea>南方基地1.1栋</coverageArea>
<isRecommend>0</isRecommend>
<distance>390.0144674166032</distance>
</hotpointInfo>
<hotpointInfo>
<name>软件产业服务中心ASW01</name>
<nasid>351214</nasid>
<address>广州市天河区科学城高普路</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.41</longitude>
<latitude>23.1781</latitude>
<coverageArea>软件产业服务中心A3区1-4F</coverageArea>
<isRecommend>0</isRecommend>
<distance>1526.5646190952175</distance>
</hotpointInfo>
<hotpointInfo>
<name>软件产业服务中心ASW02</name>
<nasid>351213</nasid>
<address>广州市天河区科学城高普路</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.41</longitude>
<latitude>23.1782</latitude>
<coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea>
<isRecommend>0</isRecommend>
<distance>1527.3123339589258</distance>
</hotpointInfo>
<hotpointInfo>
<name>车管所</name>
<nasid>353627</nasid>
<address>广州市天河区岑村华观路1732号</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3813</longitude>
<latitude>23.1697</latitude>
<coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea>
<isRecommend>0</isRecommend>
<distance>1639.8963551806467</distance>
</hotpointInfo>
<hotpointInfo>
<name>岭南职院呼叫中心东区</name>
<nasid>352009</nasid>
<address>广州天河东圃大观中路492号</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.4115</longitude>
<latitude>23.1706</latitude>
<coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea>
<isRecommend>0</isRecommend>
<distance>1831.5665734766765</distance>
</hotpointInfo>
<hotpointInfo>
<name>富域尚品居BSW02</name>
<nasid>238640</nasid>
<address>广州市黄埔区黄埔东路3689号</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.4075</longitude>
<latitude>23.165</latitude>
<coverageArea>A2座1-3F</coverageArea>
<isRecommend>0</isRecommend>
<distance>1859.005718853418</distance>
</hotpointInfo>
<hotpointInfo>
<name>华文中职6宿</name>
<nasid>350950</nasid>
<address>广州市天河区(G324)中大新华学院旁</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3865</longitude>
<latitude>23.1923</latitude>
<coverageArea>学生宿舍6</coverageArea>
<isRecommend>0</isRecommend>
<distance>1892.50686388558</distance>
</hotpointInfo>
<hotpointInfo>
<name>华文中职5宿</name>
<nasid>350951</nasid>
<address>广州市天河区(G324)中大新华学院旁</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3865</longitude>
<latitude>23.1923</latitude>
<coverageArea>学生宿舍5</coverageArea>
<isRecommend>0</isRecommend>
<distance>1892.50686388558</distance>
</hotpointInfo>
<hotpointInfo>
<name>华文中职4宿</name>
<nasid>350952</nasid>
<address>广州市天河区(G324)中大新华学院旁</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3865</longitude>
<latitude>23.1923</latitude>
<coverageArea>学生宿舍4</coverageArea>
<isRecommend>0</isRecommend>
<distance>1892.50686388558</distance>
</hotpointInfo>
<hotpointInfo>
<name>华文中职1宿</name>
<nasid>350953</nasid>
<address>广州市天河区(G324)中大新华学院旁</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3865</longitude>
<latitude>23.1923</latitude>
<coverageArea>1宿6-8F</coverageArea>
<isRecommend>0</isRecommend>
<distance>1892.50686388558</distance>
</hotpointInfo>
<hotpointInfo>
<name>华文中职教宿</name>
<nasid>350947</nasid>
<address>广州市天河区(G324)中大新华学院旁</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3866</longitude>
<latitude>23.1924</latitude>
<coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>
<isRecommend>0</isRecommend>
<distance>1897.6626410004128</distance>
</hotpointInfo>
<hotpointInfo>
<name>华文中职教学楼</name>
<nasid>350948</nasid>
<address>广州市天河区(G324)中大新华学院旁</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3865</longitude>
<latitude>23.1924</latitude>
<coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea>
<isRecommend>0</isRecommend>
<distance>1902.362099635232</distance>
</hotpointInfo>
<hotpointInfo>
<name>新华学院2SW02</name>
<nasid>353825</nasid>
<address>广州市天河区凤凰街所辖的华美路口</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3882</longitude>
<latitude>23.1932</latitude>
<coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>
<isRecommend>0</isRecommend>
<distance>1910.997494236302</distance>
</hotpointInfo>
<hotpointInfo>
<name>新华学院1SW01</name>
<nasid>353826</nasid>
<address>广州市天河区凤凰街所辖的华美路口</address>
<province>200</province>
<cityCode>440100</cityCode>
<type>99</type>
<longitude>113.3882</longitude>
<latitude>23.1932</latitude>
<coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea>
<isRecommend>0</isRecommend>
<distance>1910.997494236302</distance>
</hotpointInfo>
</hotpointInfoList>
</root>"
2.当output为:
"<?xml version="1.0" encoding="UTF-8" ?> <root> <responseHeader> <sequence>1372835359954</sequence> <timestamp>2013-07-03 15:11:05</timestamp> <version>1.0.0</version> <returnCode>0</returnCode> <errorMessage>成功</errorMessage> </responseHeader> <responsePage> <hasNextPage>false</hasNextPage> <hasPreviousPage>false</hasPreviousPage> <lastPageNumber>1</lastPageNumber> <totalCount>19</totalCount> <thisPageFirstElementNumber>1</thisPageFirstElementNumber> <thisPageLastElementNumber>19</thisPageLastElementNumber> <nextPageNumber>2</nextPageNumber> <previousPageNumber>0</previousPageNumber> <pageSize>20</pageSize> <thisPageNumber>1</thisPageNumber> <firstResult>0</firstResult> </responsePage> <hotpointInfoList> <hotpointInfo> <name>南方基地</name> <nasid>238366</nasid> <address>大观路旁天河软件园高塘园区内</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3963</longitude> <latitude>23.1771</latitude> <coverageArea>南方基地1.1栋、1.2栋</coverageArea> <isRecommend>0</isRecommend> <distance>105.75882807199615</distance> </hotpointInfo> <hotpointInfo> <name>龟背山</name> <nasid>353477</nasid> <address>位于天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <coverageArea>南方基地1.1栋</coverageArea> <isRecommend>0</isRecommend> <distance>374.05018988753386</distance> </hotpointInfo> <hotpointInfo> <name>中国移动南方基地</name> <nasid>272146</nasid> <address>广州天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <isRecommend>0</isRecommend> <distance>374.05018988753386</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW01</name> <nasid>351214</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1781</latitude> <coverageArea>软件产业服务中心A3区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1510.190977102228</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW02</name> <nasid>351213</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1782</latitude> <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1511.041725631744</distance> </hotpointInfo> <hotpointInfo> <name>车管所</name> <nasid>353627</nasid> <address>广州市天河区岑村华观路1732号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3813</longitude> <latitude>23.1697</latitude> <coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea> <isRecommend>0</isRecommend> <distance>1648.3095911436724</distance> </hotpointInfo> <hotpointInfo> <name>岭南职院呼叫中心东区</name> <nasid>352009</nasid> <address>广州天河东圃大观中路492号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4115</longitude> <latitude>23.1706</latitude> <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea> <isRecommend>0</isRecommend> <distance>1810.5506628804496</distance> </hotpointInfo> <hotpointInfo> <name>富域尚品居BSW02</name> <nasid>238640</nasid> <address>广州市黄埔区黄埔东路3689号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4075</longitude> <latitude>23.165</latitude> <coverageArea>A2座1-3F</coverageArea> <isRecommend>0</isRecommend> <distance>1837.7807562784299</distance> </hotpointInfo> <hotpointInfo> <name>华文中职6宿</name> <nasid>350950</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍6</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职5宿</name> <nasid>350951</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍5</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职4宿</name> <nasid>350952</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍4</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职1宿</name> <nasid>350953</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>1宿6-8F</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教宿</name> <nasid>350947</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3866</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1917.0689651951118</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教学楼</name> <nasid>350948</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1921.8129564597668</distance> </hotpointInfo> <hotpointInfo> <name>新华学院2SW02</name> <nasid>353825</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1929.3985939077031</distance> </hotpointInfo> <hotpointInfo> <name>新华学院1SW01</name> <nasid>353826</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1929.3985939077031</distance> </hotpointInfo> <hotpointInfo> <name>岭南学院南区A学生宿舍新南一栋SW01</name> <nasid>352002</nasid> <address>广州市萝岗区大观中路与科学大道交界处</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4121</longitude> <latitude>23.168</latitude> <coverageArea>学生宿舍新南一栋5F-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1996.9030436473365</distance> </hotpointInfo> <hotpointInfo> <name>岭南学院西区A</name> <nasid>352003</nasid> <address>广州萝岗区大观中路新泰商业街直入</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4121</longitude> <latitude>23.168</latitude> <coverageArea>东1栋宿舍1F-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1996.9030436473365</distance> </hotpointInfo> <hotpointInfo> <name>岭南学院南区A学生公寓南二栋SW02</name> <nasid>352004</nasid> <address>广州市萝岗区大观中路与科学大道交界处</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4121</longitude> <latitude>23.168</latitude> <coverageArea>学生公寓南二栋、南一栋、南三栋4F-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1996.9030436473365</distance> </hotpointInfo> </hotpointInfoList> </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" ?> <root> <responseHeader> <sequence>1372835359954</sequence> <timestamp>2013-07-03 15:11:05</timestamp> <version>1.0.0</version> <returnCode>0</returnCode> <errorMessage>成功</errorMessage> </responseHeader> <responsePage> <hasNextPage>false</hasNextPage> <hasPreviousPage>false</hasPreviousPage> <lastPageNumber>1</lastPageNumber> <totalCount>19</totalCount> <thisPageFirstElementNumber>1</thisPageFirstElementNumber> <thisPageLastElementNumber>19</thisPageLastElementNumber> <nextPageNumber>2</nextPageNumber> <previousPageNumber>0</previousPageNumber> <pageSize>20</pageSize> <thisPageNumber>1</thisPageNumber> <firstResult>0</firstResult> </responsePage> <hotpointInfoList> <hotpointInfo> <name>南方基地</name> <nasid>238366</nasid> <address>大观路旁天河软件园高塘园区内</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3963</longitude> <latitude>23.1771</latitude> <coverageArea>南方基地1.1栋、1.2栋</coverageArea> <isRecommend>0</isRecommend> <distance>105.75882807199615</distance> </hotpointInfo> <hotpointInfo> <name>龟背山</name> <nasid>353477</nasid> <address>位于天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <coverageArea>南方基地1.1栋</coverageArea> <isRecommend>0</isRecommend> <distance>374.05018988753386</distance> </hotpointInfo> <hotpointInfo> <name>中国移动南方基地</name> <nasid>272146</nasid> <address>广州天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <isRecommend>0</isRecommend> <distance>374.05018988753386</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW01</name> <nasid>351214</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1781</latitude> <coverageArea>软件产业服务中心A3区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1510.190977102228</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW02</name> <nasid>351213</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1782</latitude> <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1511.041725631744</distance> </hotpointInfo> <hotpointInfo> <name>车管所</name> <nasid>353627</nasid> <address>广州市天河区岑村华观路1732号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3813</longitude> <latitude>23.1697</latitude> <coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea> <isRecommend>0</isRecommend> <distance>1648.3095911436724</distance> </hotpointInfo> <hotpointInfo> <name>岭南职院呼叫中心东区</name> <nasid>352009</nasid> <address>广州天河东圃大观中路492号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4115</longitude> <latitude>23.1706</latitude> <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea> <isRecommend>0</isRecommend> <distance>1810.5506628804496</distance> </hotpointInfo> <hotpointInfo> <name>富域尚品居BSW02</name> <nasid>238640</nasid> <address>广州市黄埔区黄埔东路3689号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4075</longitude> <latitude>23.165</latitude> <coverageArea>A2座1-3F</coverageArea> <isRecommend>0</isRecommend> <distance>1837.7807562784299</distance> </hotpointInfo> <hotpointInfo> <name>华文中职6宿</name> <nasid>350950</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍6</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职5宿</name> <nasid>350951</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍5</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职4宿</name> <nasid>350952</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍4</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职1宿</name> <nasid>350953</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>1宿6-8F</coverageArea> <isRecommend>0</isRecommend> <distance>1911.9829741274648</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教宿</name> <nasid>350947</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3866</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1917.0689651951118</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教学楼</name> <nasid>350948</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1921.8129564597668</distance> </hotpointInfo> <hotpointInfo> <name>新华学院2SW02</name> <nasid>353825</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1929.3985939077031</distance> </hotpointInfo> <hotpointInfo> <name>新华学院1SW01</name> <nasid>353826</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1929.3985939077031</distance> </hotpointInfo> <hotpointInfo> <name>岭南学院南区A学生宿舍新南一栋SW01</name> <nasid>352002</nasid> <address>广州市萝岗区大观中路与科学大道交界处</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4121</longitude> <latitude>23.168</latitude> <coverageArea>学生宿舍新南一栋5F-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1996.9030436473365</distance> </hotpointInfo> <hotpointInfo> <name>岭南学院西区A</name> <nasid>352003</nasid> <address>广州萝岗区大观中路新泰商业街直入</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4121</longitude> <latitude>23.168</latitude> <coverageArea>东1栋宿舍1F-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1996.9030436473365</distance> </hotpointInfo> <hotpointInfo> <name>岭南学院南区A学生公寓南二栋SW02</name> <nasid>352004</nasid> <address>广州市萝岗区大观中路与科学大道交界处</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4121</longitude> <latitude>23.168</latitude> <coverageArea>学生公寓南二栋、南一栋、南三栋4F-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1996.9030436473365</distance> </hotpointInfo> </hotpointInfoList> </root>"; //output = "<?xml version="1.0" encoding="UTF-8" ?> <root> <responseHeader> <sequence>1372834735931</sequence> <timestamp>2013-07-03 15:02:37</timestamp> <version>1.0.0</version> <returnCode>0</returnCode> <errorMessage>成功</errorMessage> </responseHeader> <responsePage> <hasNextPage>false</hasNextPage> <hasPreviousPage>false</hasPreviousPage> <lastPageNumber>1</lastPageNumber> <totalCount>16</totalCount> <thisPageFirstElementNumber>1</thisPageFirstElementNumber> <thisPageLastElementNumber>16</thisPageLastElementNumber> <nextPageNumber>2</nextPageNumber> <previousPageNumber>0</previousPageNumber> <pageSize>20</pageSize> <thisPageNumber>1</thisPageNumber> <firstResult>0</firstResult> </responsePage> <hotpointInfoList> <hotpointInfo> <name>南方基地</name> <nasid>238366</nasid> <address>大观路旁天河软件园高塘园区内</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3963</longitude> <latitude>23.1771</latitude> <coverageArea>南方基地1.1栋、1.2栋</coverageArea> <isRecommend>0</isRecommend> <distance>123.84223184290781</distance> </hotpointInfo> <hotpointInfo> <name>中国移动南方基地</name> <nasid>272146</nasid> <address>广州天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <isRecommend>0</isRecommend> <distance>390.0144674166032</distance> </hotpointInfo> <hotpointInfo> <name>龟背山</name> <nasid>353477</nasid> <address>位于天河软件园高唐新建区西部</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3989</longitude> <latitude>23.1775</latitude> <coverageArea>南方基地1.1栋</coverageArea> <isRecommend>0</isRecommend> <distance>390.0144674166032</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW01</name> <nasid>351214</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1781</latitude> <coverageArea>软件产业服务中心A3区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1526.5646190952175</distance> </hotpointInfo> <hotpointInfo> <name>软件产业服务中心ASW02</name> <nasid>351213</nasid> <address>广州市天河区科学城高普路</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.41</longitude> <latitude>23.1782</latitude> <coverageArea>软件产业服务中心A 1-2区1-4F</coverageArea> <isRecommend>0</isRecommend> <distance>1527.3123339589258</distance> </hotpointInfo> <hotpointInfo> <name>车管所</name> <nasid>353627</nasid> <address>广州市天河区岑村华观路1732号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3813</longitude> <latitude>23.1697</latitude> <coverageArea>岑村车管所的交通管理中心1F大堂,交通管理中心9F会议室</coverageArea> <isRecommend>0</isRecommend> <distance>1639.8963551806467</distance> </hotpointInfo> <hotpointInfo> <name>岭南职院呼叫中心东区</name> <nasid>352009</nasid> <address>广州天河东圃大观中路492号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4115</longitude> <latitude>23.1706</latitude> <coverageArea>覆盖4F办公室、实操培训室、班前会议室、招待室一带区域、5F班前会议室、代维办、招待区、话务区一带区域</coverageArea> <isRecommend>0</isRecommend> <distance>1831.5665734766765</distance> </hotpointInfo> <hotpointInfo> <name>富域尚品居BSW02</name> <nasid>238640</nasid> <address>广州市黄埔区黄埔东路3689号</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.4075</longitude> <latitude>23.165</latitude> <coverageArea>A2座1-3F</coverageArea> <isRecommend>0</isRecommend> <distance>1859.005718853418</distance> </hotpointInfo> <hotpointInfo> <name>华文中职6宿</name> <nasid>350950</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍6</coverageArea> <isRecommend>0</isRecommend> <distance>1892.50686388558</distance> </hotpointInfo> <hotpointInfo> <name>华文中职5宿</name> <nasid>350951</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍5</coverageArea> <isRecommend>0</isRecommend> <distance>1892.50686388558</distance> </hotpointInfo> <hotpointInfo> <name>华文中职4宿</name> <nasid>350952</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>学生宿舍4</coverageArea> <isRecommend>0</isRecommend> <distance>1892.50686388558</distance> </hotpointInfo> <hotpointInfo> <name>华文中职1宿</name> <nasid>350953</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1923</latitude> <coverageArea>1宿6-8F</coverageArea> <isRecommend>0</isRecommend> <distance>1892.50686388558</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教宿</name> <nasid>350947</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3866</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1897.6626410004128</distance> </hotpointInfo> <hotpointInfo> <name>华文中职教学楼</name> <nasid>350948</nasid> <address>广州市天河区(G324)中大新华学院旁</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3865</longitude> <latitude>23.1924</latitude> <coverageArea>宿舍楼1栋1F、3-8F,宿舍楼4栋2-6F,教师宿舍楼1-6F,教学楼1-6F</coverageArea> <isRecommend>0</isRecommend> <distance>1902.362099635232</distance> </hotpointInfo> <hotpointInfo> <name>新华学院2SW02</name> <nasid>353825</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1910.997494236302</distance> </hotpointInfo> <hotpointInfo> <name>新华学院1SW01</name> <nasid>353826</nasid> <address>广州市天河区凤凰街所辖的华美路口</address> <province>200</province> <cityCode>440100</cityCode> <type>99</type> <longitude>113.3882</longitude> <latitude>23.1932</latitude> <coverageArea>中山大学新华学院的A、B、C、D四座教学楼的一至五层</coverageArea> <isRecommend>0</isRecommend> <distance>1910.997494236302</distance> </hotpointInfo> </hotpointInfoList> </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的能力,尤其针对复杂的正则表达式
将复杂的,大的问题拆分成小问题,相信计算机,对于处理针对化问题的能力,还是值得信赖的!