这是我的解析源,我将其插入到下面的数据库中
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<Count>2</Count>
<Filters>
<MEMBER_UNI>1775W585_2/00323</MEMBER_UNI>
</Filters>
<Placemark id="placemarkfe0f3016-37e1-4c7d-b453-2d9a3fbd4947">
<name>streetLighting.lightingPoint</name>
<guid>fe0f3016-37e1-4c7d-b453-2d9a3fbd4947</guid>
<description>geom</description>
<Point>
<coordinates>-1.0542558191173,50.834675625281</coordinates>
</Point>
<GlobalID>dbfedcfd-c0d6-494c-8d9d-0204dbdb8157</GlobalID>
<IIT_ID_C_1>1</IIT_ID_C_1>
<IIT_X_SE_1>1</IIT_X_SE_1>
</Placemark>
<Placemark id="placemark5b53ebbf-3672-4b29-a702-f44a96fed4be">
<name>streetLighting.lightingPoint</name>
<guid>5b53ebbf-3672-4b29-a702-f44a96fed4be</guid>
<description>geom</description>
<Point>
<coordinates>-1.0542861954769,50.834426772517</coordinates>
</Point>
<GlobalID>3e485808-7b64-4e5f-95a8-94cd90aea900</GlobalID>
<IIT_ID_C_1>Feb-29</IIT_ID_C_1>
<IIT_X_SE_1>2</IIT_X_SE_1>
</Placemark>
</Document>
</kml>
下面是我的代码,应该更改,有什么想法吗?我需要避免
protected Void doInBackground(Void... arg0) {
XmlResourceParser parser = context.getResources().getXml(R.xml.test1);
databaseHelper myDbHelper = new databaseHelper(context);
try {
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("Placemark") || name.equals("Count")) {
String id = null, gname = null, pob = null, pob1 = null, memb = null, seq = null, site = null;
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
name = parser.getName();
if (name.equals("name")) {
id = readText(parser);
} else if (name.equals("description")) {
parser.next();
parser.nextTag();
} else if (name.equals("guid")) {
gname = readText(parser);
} else if (name.equals("Point")) {
parser.nextTag();
if (parser.getName().equals("coordinates")) {
pob = readText(parser);
String[] pobarray = pob.split(",");
String part1 = pobarray[0];
String part2 = pobarray[1];
pob1 = part2;
pob = part1;
parser.nextTag();
}
} else if (name.equals("MEMBER_UNI")) {
memb = readText(parser);
} else if (name.equals("IIT_ID_C_1")) {
seq = readText(parser);
} else if (name.equals("IIT_X_SE_1")) {
site = readText(parser);
}
}
myDbHelper.insertData(id, gname, pob, pob1, memb, seq, site);
}
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (myDbHelper != null) {
myDbHelper.close();
}
}
return null;
}
在我看来,应该将其更改为更简单、更聪明的东西。