use of org.xmlpull.v1.XmlPullParser in project android-maps-utils by googlemaps.
the class KmlFeatureParserTest method testExtendedData.
public void testExtendedData() throws Exception {
XmlPullParser xmlPullParser = createParser(R.raw.amu_multiple_placemarks);
KmlPlacemark placemark = KmlFeatureParser.createPlacemark(xmlPullParser);
assertNotNull(placemark.getProperty("holeNumber"));
}
use of org.xmlpull.v1.XmlPullParser in project android-maps-utils by googlemaps.
the class KmlFeatureParserTest method testProperties.
public void testProperties() throws Exception {
XmlPullParser xmlPullParser = createParser(R.raw.amu_multigeometry_placemarks);
KmlPlacemark placemark = KmlFeatureParser.createPlacemark(xmlPullParser);
assertTrue(placemark.hasProperties());
assertEquals(placemark.getProperty("name"), "Placemark Test");
assertNull(placemark.getProperty("description"));
}
use of org.xmlpull.v1.XmlPullParser in project android-maps-utils by googlemaps.
the class KmlFeatureParserTest method testMultiGeometries.
public void testMultiGeometries() throws Exception {
XmlPullParser xmlPullParser = createParser(R.raw.amu_nested_multigeometry);
KmlPlacemark feature = KmlFeatureParser.createPlacemark(xmlPullParser);
assertEquals(feature.getProperty("name"), "multiPointLine");
assertEquals(feature.getProperty("description"), "Nested MultiGeometry structure");
assertEquals(feature.getGeometry().getGeometryType(), "MultiGeometry");
ArrayList<Geometry> objects = (ArrayList<Geometry>) feature.getGeometry().getGeometryObject();
assertEquals(objects.get(0).getGeometryType(), "Point");
assertEquals(objects.get(1).getGeometryType(), "LineString");
assertEquals(objects.get(2).getGeometryType(), "MultiGeometry");
ArrayList<Geometry> subObjects = (ArrayList<Geometry>) objects.get(2).getGeometryObject();
assertEquals(subObjects.get(0).getGeometryType(), "Point");
assertEquals(subObjects.get(1).getGeometryType(), "LineString");
}
use of org.xmlpull.v1.XmlPullParser in project j2objc by google.
the class Driver method parseSubTree.
public void parseSubTree(XmlPullParser pp) throws SAXException, IOException {
this.pp = pp;
final boolean namespaceAware = pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES);
try {
if (pp.getEventType() != XmlPullParser.START_TAG) {
throw new SAXException("start tag must be read before skiping subtree" + pp.getPositionDescription());
}
final int[] holderForStartAndLength = new int[2];
final StringBuilder rawName = new StringBuilder(16);
String prefix = null;
String name = null;
int level = pp.getDepth() - 1;
int type = XmlPullParser.START_TAG;
LOOP: do {
switch(type) {
case XmlPullParser.START_TAG:
if (namespaceAware) {
final int depth = pp.getDepth() - 1;
final int countPrev = (level > depth) ? pp.getNamespaceCount(depth) : 0;
//int countPrev = pp.getNamespaceCount(pp.getDepth() - 1);
final int count = pp.getNamespaceCount(depth + 1);
for (int i = countPrev; i < count; i++) {
contentHandler.startPrefixMapping(pp.getNamespacePrefix(i), pp.getNamespaceUri(i));
}
name = pp.getName();
prefix = pp.getPrefix();
if (prefix != null) {
rawName.setLength(0);
rawName.append(prefix);
rawName.append(':');
rawName.append(name);
}
startElement(pp.getNamespace(), name, // TODO Fixed this. Was "not equals".
prefix == null ? name : rawName.toString());
} else {
startElement(pp.getNamespace(), pp.getName(), pp.getName());
}
break;
case XmlPullParser.TEXT:
{
final char[] chars = pp.getTextCharacters(holderForStartAndLength);
contentHandler.characters(chars, //start
holderForStartAndLength[0], //len
holderForStartAndLength[1]);
}
break;
case XmlPullParser.END_TAG:
//--level;
if (namespaceAware) {
name = pp.getName();
prefix = pp.getPrefix();
if (prefix != null) {
rawName.setLength(0);
rawName.append(prefix);
rawName.append(':');
rawName.append(name);
}
contentHandler.endElement(pp.getNamespace(), name, prefix != null ? name : rawName.toString());
// when entering show prefixes for all levels!!!!
final int depth = pp.getDepth();
final int countPrev = (level > depth) ? pp.getNamespaceCount(pp.getDepth()) : 0;
int count = pp.getNamespaceCount(pp.getDepth() - 1);
// undeclare them in reverse order
for (int i = count - 1; i >= countPrev; i--) {
contentHandler.endPrefixMapping(pp.getNamespacePrefix(i));
}
} else {
contentHandler.endElement(pp.getNamespace(), pp.getName(), pp.getName());
}
break;
case XmlPullParser.END_DOCUMENT:
break LOOP;
}
type = pp.next();
} while (pp.getDepth() > level);
} catch (XmlPullParserException ex) {
final SAXParseException saxException = new SAXParseException("parsing error: " + ex, this, ex);
ex.printStackTrace();
errorHandler.fatalError(saxException);
}
}
use of org.xmlpull.v1.XmlPullParser in project AndroidSDK-RecipeBook by gabu.
the class Recipe078 method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 名古屋の明日の天気情報を取得できるURLです。
String uri = "http://weather.livedoor.com/forecast/" + "webservice/rest/v1?city=38&day=tomorrow";
// HTTPクライアントを作って
HttpClient client = new DefaultHttpClient();
// GETオブジェクトを作って
HttpGet get = new HttpGet();
try {
// URIをセット
get.setURI(new URI(uri));
// GETリクエストを実行してレスポンスを取得
HttpResponse res = client.execute(get);
// レスポンスからInputStreamを取得
InputStream in = res.getEntity().getContent();
// XMLプルパーサを生成して
XmlPullParser parser = Xml.newPullParser();
// InputStreamをセット
parser.setInput(in, "UTF-8");
int eventType = parser.getEventType();
// イベントタイプがEND_DOCUMENTになるまでループ
// けど、以下の必要な値が全て取得できたらbreakする。
String title = "";
String telop = "";
String description = "";
while (eventType != XmlPullParser.END_DOCUMENT) {
switch(eventType) {
case XmlPullParser.START_TAG:
String tag = parser.getName();
if ("title".equals(tag)) {
// タイトルを取得
title = parser.nextText();
} else if ("telop".equals(tag)) {
// 天気を取得
telop = parser.nextText();
} else if ("description".equals(tag)) {
// 天気概況文を取得
description = parser.nextText();
}
break;
}
if (!("".equals(title) || "".equals(telop) || "".equals(description))) {
// 必要な値が取得できたらループを抜ける
break;
}
// パーサを次のイベントまで進める
eventType = parser.next();
}
// TextViewに表示!
TextView v = (TextView) findViewById(R.id.text);
v.setText(title + "\n\n" + telop + "\n\n" + description);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
Aggregations