我做了一个课来解析室内的GML信息。室内GML有5层。 所有部件都有效。 在第五层,我需要调用一个名为posList的标签:
<indoorCore:CellSpace gml:id='L5C1'>
<indoorCore:Geometry2D>
<gml:Polygon >
<gml:exterior>
<gml:LinearRing>
<gml:posList>529.0 840.25 529.0 803.51 540.0 803.51</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</indoorCore:Geometry2D>
<indoorCore:PartialboundedBy>
<indoorCore:CellSpaceBoundary gml:id='L5B1'>
<indoorCore:geometry2D>
<gml:LineString>
<gml:posList>540.0 803.51 529.0 803.51 529.0 840.25</gml:posList>
</gml:LineString>
</indoorCore:geometry2D>
<indoorCore:duality>
<indoorCore:Transition xlink:href='#L5T1'/>
</indoorCore:duality>
</indoorCore:CellSpaceBoundary>
我需要标签posList里面的标签多边形内的点。我写了这样的解析:
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
currentTagName = parser.getName();
if (currentTagName.equals("gml:Polygon")) {
inPolygon = true;
} else if (currentTagName.equals("indoorCore:SpaceLayer")) {
String layer = parser.getAttributeValue(0);
currentLayer = layer;
if (layer.equals("L5")) {
startOfFifthLayer = true;
}
} else if(currentTagName.equals("gml:name")) {
inName = true;
// inNodes=true;
// Log.d("name", "true");
}
if(currentTagName.equals("gml:posList")) {
inLayerFivePolygon = true;
Log.d("Polygon5", "true");
}
break;
case XmlPullParser.END_TAG:
if (currentTagName.equals("indoorCore:SpaceLayer")) {
String layer = parser.getAttributeValue(0);
currentLayer = layer;
currentTagName = parser.getName();
if(currentLayer.equals("L5")) {
endOfFifthLayer = true;
}
}
break;
case XmlPullParser.TEXT:
if (inName) {
// put posList points in an array
String points = parser.getText();
Log.d("PlaceName MapPlace", points);
String[] split = points.split(" ");
inName=false;
} else if(inLayerFivePolygon){
String points = parser.getText();
Log.d("Area MapPlace", points);
String[] split = points.split(" ");
inLayerFivePolygon=false;
}
break;
}
if (endOfFifthLayer) {
break;
}
eventType = parser.next();
}
}
当我只解析标签posList时,我的程序可以读取这些点。但是,当我想过滤它并将其放在多边形标记内时,它不会在日志中显示给我的点。
你知道诀窍是什么吗? 非常感谢!
答案 0 :(得分:1)
我通过更改XmlPullParser.START_TAG案例中测试图层的条件来解决它:
else if (currentTagName.equals("indoorCore:SpaceLayer")) {
String layer = parser.getAttributeValue(0);
currentLayer = layer;
if (!layer.equals("L5")) {
inFifthLayer = false;
}else {
inFifthLayer = true;
startOfFifthLayer = true;
}
然后为了控制标签,而且测试标签,我再次控制图层,如下所示:
if(currentTagName.equals("gml:posList") && inFifthLayer) {
inLayerFivePolygon = true;
Log.d("Polygon5", "true");
}
最后在XmlPullParser.TEXT中,我解析了我需要的点:
XmlPullParser.TEXT:
if(inLayerFivePolygon){
String points = parser.getText();
String[] split = points.split(" ");
//ArrayList<String> finalPoints = convertToPolygon(points);
// Log.d("Area MapPlace", finalPoints.toString());
Log.d("Area MapPlace2", points);
inLayerFivePolygon=false;
}