解决问题之,wp项目中使用MatchCollection正则表达式匹配出错

前端之家收集整理的这篇文章主要介绍了解决问题之,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,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,"<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>();
                                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的能力,尤其针对复杂的正则表达式

将复杂的,大的问题拆分成小问题,相信计算机,对于处理针对化问题的能力,还是值得信赖的!

原文链接:https://www.f2er.com/regex/362782.html

猜你在找的正则表达式相关文章