Author: Flyingis
XML has become a data transmission standard. parsing XML is the basic function of any language. to parse XML, You need to first understand the xml composition structure and Traversal method. You can search for XML on the Internet. One of the main scenarios for parsing XML using ArcGIS Flex APIS is that in the "Callback" phase, GeoRSSUtil. as in Demo "Reading GeoRSS feeds" contains some basic application methods.
Code
Package com. esri. ags. samples
{
Import com. esri. ags. geometry. Geometry;
Import com. esri. ags. geometry. MapPoint;
Import com. esri. ags. geometry. Polygon;
Import mx. utils. StringUtil;
Public class GeoRSSUtil
{
Private static const GEORSS: Namespace = Namespaces. GEORSS_NS;
Private static const GEOWGS: Namespace = Namespaces. GEOWGS_NS;
Private static const GEO: Namespace = Namespaces. GEO_NS;
Private static const GML: Namespace = Namespaces. GML_NS;
Public function GeoRSSUtil (singletonEnforcer: SingletonEnforcer)
{
}
Public static function toGeometry (x: XML): Geometry
{
Const geoLat: String = String (x. GEOWGS: lat );
Const geoLon: String = String (x. GEOWGS: long );
If (geoLat & geoLon)
{
Return new MapPoint (Number (geoLon), Number (geoLat ));
}
Const georssPoint: String = String (x. GEORSS: point );
If (georssPoint)
{
Return parseGeoRSSPoint (georssPoint );
}
Const pointList: XMLList = x. GEO: point;
If (pointList & pointList. length ()> 0)
{
Const geoPoint: XML = pointList [0];
Const geoPLat: Number = Number (geoPoint. GEO: lat );
Const geoPLon: Number = Number (geoPoint. GEO: long );
Return new MapPoint (geoPLon, geoPLat );
}
Const georsspolympus Gon: String = String (x. GEORSS: polygon );
If (georsspolympus gon)
{
Return parsegeorsspolympus Gon (georsspolympus gon );
}
Const whereList: XMLList = x. GEORSS: where;
If (whereList & whereList. length ()> 0)
{
Const pos: String = whereList [0]. GML: Point [0]. GML: pos [0];
Const arr: Array = pos. split ("");
Const gmlLat: Number = Number (arr [0]);
Const gmlLon: Number = Number (arr [1]);
Return new MapPoint (gmlLon, gmlLat );
}
Return null;
}
Private static function parseGeoRSSWhere (x: XML): Geometry
{
Return null;
}
Private static function parseGeoRSSPoint (text: String): Geometry
{
Const tokens: Array = StringUtil. trim (text). split ("");
Const lat: Number = Number (tokens [0]);
Const lon: Number = Number (tokens [1]);
Return new MapPoint (lon, lat );
}
Private static function parsegeorsspolympus Gon (text: String): Geometry
{
Const path: Array = [];
Const tokens: Array = StringUtil. trim (text). split ("");
For (var I: int = 0, j: int = 1; j <tokens. length; I + = 2, j + = 2)
{
Var lat: Number = Number (tokens [I]);
Var lon: Number = Number (tokens [j]);
Path. push (new MapPoint (lon, lat ));
}
Return new Polygon ([path]);
}
}
}
Class SingletonEnforcer
{
}
XML parsing in the Chinese encoding is often encountered a problem, but never let it happen-UTF-8, please refer to the two articles: http://www.asflex.cn /? P = 428
Http://bbs.blueidea.com/thread-2887754-1-1.html
Speaking of GeoRSS, GeoRSS is a method of geographic location search and aggregation. It displays the geographic location of the current message on a map and marks it out. When you click query, you can access the specific content of the message, for example, the location of the meeting is identified by GeoRSS on the map, and information can be mined after clicking it. Before June January, I found the specific location and time of the Oracle Developer Conference through GeoRSS.