Search in sources :

Example 56 with XmlPullParser

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"));
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 57 with XmlPullParser

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"));
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 58 with XmlPullParser

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");
}
Also used : Geometry(com.google.maps.android.data.Geometry) XmlPullParser(org.xmlpull.v1.XmlPullParser) ArrayList(java.util.ArrayList)

Example 59 with XmlPullParser

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);
    }
}
Also used : SAXParseException(org.xml.sax.SAXParseException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) SAXException(org.xml.sax.SAXException)

Example 60 with XmlPullParser

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();
    }
}
Also used : InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) XmlPullParser(org.xmlpull.v1.XmlPullParser) HttpResponse(org.apache.http.HttpResponse) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) TextView(android.widget.TextView) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

XmlPullParser (org.xmlpull.v1.XmlPullParser)673 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)623 IOException (java.io.IOException)377 FileInputStream (java.io.FileInputStream)185 FileNotFoundException (java.io.FileNotFoundException)185 File (java.io.File)107 ArrayList (java.util.ArrayList)77 StringReader (java.io.StringReader)65 AttributeSet (android.util.AttributeSet)61 Test (org.junit.Test)57 TypedArray (android.content.res.TypedArray)56 InputStream (java.io.InputStream)48 AtomicFile (android.util.AtomicFile)47 HashMap (java.util.HashMap)45 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)39 FileReader (java.io.FileReader)36 BufferedInputStream (java.io.BufferedInputStream)30 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)30 RemoteException (android.os.RemoteException)28 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)28