Search in sources :

Example 46 with KXmlParser

use of org.kxml2.io.KXmlParser in project ETSMobile-Android2 by ApplETS.

the class ExtendedSoapSerializationEnvelope method GetSoapObject.

public SoapObject GetSoapObject(Element detailElement) {
    try {
        XmlSerializer xmlSerializer = XmlPullParserFactory.newInstance().newSerializer();
        StringWriter writer = new StringWriter();
        xmlSerializer.setOutput(writer);
        detailElement.write(xmlSerializer);
        xmlSerializer.flush();
        XmlPullParser xpp = new KXmlParser();
        xpp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        xpp.setInput(new StringReader(writer.toString()));
        xpp.nextTag();
        SoapObject soapObj = new SoapObject(detailElement.getNamespace(), detailElement.getName());
        readSerializable(xpp, soapObj);
        return soapObj;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) StringWriter(java.io.StringWriter) SoapObject(org.ksoap2.serialization.SoapObject) XmlPullParser(org.xmlpull.v1.XmlPullParser) StringReader(java.io.StringReader) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 47 with KXmlParser

use of org.kxml2.io.KXmlParser in project collect by opendatakit.

the class OpenRosaXmlFetcher method getXML.

/**
 * Gets an XML document for a given url
 *
 * @param urlString - url of the XML document
 * @return DocumentFetchResult - an object that contains the results of the "get" operation
 */
@SuppressWarnings("PMD.AvoidRethrowingException")
public DocumentFetchResult getXML(String urlString) throws Exception {
    // parse response
    Document doc;
    HttpGetResult inputStreamResult;
    try {
        inputStreamResult = fetch(urlString, HTTP_CONTENT_TYPE_TEXT_XML);
        if (inputStreamResult.getStatusCode() != HttpURLConnection.HTTP_OK) {
            String error = "getXML failed while accessing " + urlString + " with status code: " + inputStreamResult.getStatusCode();
            Timber.e(error);
            return new DocumentFetchResult(error, inputStreamResult.getStatusCode());
        }
        try (InputStream resultInputStream = inputStreamResult.getInputStream();
            InputStreamReader streamReader = new InputStreamReader(resultInputStream, "UTF-8")) {
            doc = new Document();
            KXmlParser parser = new KXmlParser();
            parser.setInput(streamReader);
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
            doc.parse(parser);
        }
    } catch (Exception e) {
        throw e;
    }
    return new DocumentFetchResult(doc, inputStreamResult.isOpenRosaResponse(), inputStreamResult.getHash());
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) InputStreamReader(java.io.InputStreamReader) DocumentFetchResult(org.odk.collect.android.utilities.DocumentFetchResult) InputStream(java.io.InputStream) Document(org.kxml2.kdom.Document) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException)

Example 48 with KXmlParser

use of org.kxml2.io.KXmlParser in project OsmAnd-tools by osmandapp.

the class OsmAndServerMonitorTasks method countMapsInMapIndex.

private int countMapsInMapIndex(InputStream is) throws IOException, XmlPullParserException {
    int mapCounter = 0;
    XmlPullParser xpp = new KXmlParser();
    xpp.setInput(new InputStreamReader(is));
    int eventType = xpp.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
            if (xpp.getAttributeValue(0).equals("map")) {
                mapCounter++;
            }
        }
        if (eventType == XmlPullParser.TEXT) {
            if (!xpp.isWhitespace()) {
                throw new XmlPullParserException("Text in document");
            }
        }
        eventType = xpp.next();
    }
    return mapCounter;
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) InputStreamReader(java.io.InputStreamReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

KXmlParser (org.kxml2.io.KXmlParser)48 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)25 XmlPullParser (org.xmlpull.v1.XmlPullParser)21 IOException (java.io.IOException)19 InputStreamReader (java.io.InputStreamReader)8 StringReader (java.io.StringReader)8 Document (org.kxml2.kdom.Document)6 InputStream (java.io.InputStream)5 URL (java.net.URL)5 FileInputStream (java.io.FileInputStream)4 MalformedURLException (java.net.MalformedURLException)4 File (java.io.File)3 URISyntaxException (java.net.URISyntaxException)3 URLConnection (java.net.URLConnection)3 DocumentImpl (org.apache.harmony.xml.dom.DocumentImpl)3 MetadataUpdateException (org.opendatakit.briefcase.model.MetadataUpdateException)3 XmlAttribute (com.intellij.psi.xml.XmlAttribute)2 XmlFile (com.intellij.psi.xml.XmlFile)2 XmlTag (com.intellij.psi.xml.XmlTag)2 FileNotFoundException (java.io.FileNotFoundException)2