org.xmlpull.v1.XmlPullParserFactory Java Examples
The following examples show how to use
org.xmlpull.v1.XmlPullParserFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlToJson.java From alipay-master with GNU General Public License v3.0 | 6 votes |
private @Nullable JSONObject convertToJSONObject() { try { Tag parentTag = new Tag("", "xml"); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(false); // tags with namespace are taken as-is ("namespace:tagname") XmlPullParser xpp = factory.newPullParser(); setInput(xpp); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.START_DOCUMENT) { eventType = xpp.next(); } readTags(parentTag, xpp); unsetInput(); return convertTagToJson(parentTag, false); } catch (XmlPullParserException | IOException e) { e.printStackTrace(); return null; } }
Example #2
Source File: XMLTVParser.java From ChannelSurfer with MIT License | 6 votes |
public static List<Program> parse(String in) throws XmlPullParserException, IOException { try { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); Log.d(TAG, "Start parsing"); Log.d(TAG, in.substring(0, 36)); xpp.setInput(new StringReader(in)); int eventType = xpp.getEventType(); Log.d(TAG, eventType+""); // if(eventType == XmlPullParser.START_DOCUMENT) // xpp.next(); /* xpp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); xpp.setInput(new InputStreamReader(in));*/ /*xpp.nextTag(); xpp.nextTag(); */return readFeed(xpp); } finally { // in.close(); } }
Example #3
Source File: Rss2Parser.java From PkRSS with Apache License 2.0 | 6 votes |
public Rss2Parser() { // Initialize DateFormat object with the default date formatting dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US); dateFormat.setTimeZone(Calendar.getInstance().getTimeZone()); pattern = Pattern.compile("-\\d{1,4}x\\d{1,4}"); // Initialize XmlPullParser object with a common configuration XmlPullParser parser = null; try { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(false); parser = factory.newPullParser(); } catch (XmlPullParserException e) { e.printStackTrace(); } xmlParser = parser; }
Example #4
Source File: ExtendedSoapSerializationEnvelope.java From ETSMobile-Android2 with Apache License 2.0 | 6 votes |
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; }
Example #5
Source File: XmlToJson.java From XmlToJson with Apache License 2.0 | 6 votes |
private @Nullable JSONObject convertToJSONObject() { try { Tag parentTag = new Tag("", "xml"); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(false); // tags with namespace are taken as-is ("namespace:tagname") XmlPullParser xpp = factory.newPullParser(); setInput(xpp); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.START_DOCUMENT) { eventType = xpp.next(); } readTags(parentTag, xpp); unsetInput(); return convertTagToJson(parentTag, false); } catch (XmlPullParserException | IOException e) { e.printStackTrace(); return null; } }
Example #6
Source File: XmlWriter.java From osmapi with GNU Lesser General Public License v3.0 | 6 votes |
@Override public final void write(OutputStream out) throws IOException { try { xml = XmlPullParserFactory.newInstance().newSerializer(); } catch(XmlPullParserException e) { throw new RuntimeException("Cannot initialize serializer", e); } xml.setOutput(out, CHARSET); xml.startDocument(CHARSET, null); write(); if(xml.getName() != null) { throw new IllegalStateException("Forgot to close a tag"); } xml.endDocument(); xml.flush(); }
Example #7
Source File: SliceManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public byte[] getBackupPayload(int user) { if (Binder.getCallingUid() != SYSTEM_UID) { throw new SecurityException("Caller must be system"); } //TODO: http://b/22388012 if (user != UserHandle.USER_SYSTEM) { Slog.w(TAG, "getBackupPayload: cannot backup policy for user " + user); return null; } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { XmlSerializer out = XmlPullParserFactory.newInstance().newSerializer(); out.setOutput(baos, Encoding.UTF_8.name()); mPermissions.writeBackup(out); out.flush(); return baos.toByteArray(); } catch (IOException | XmlPullParserException e) { Slog.w(TAG, "getBackupPayload: error writing payload for user " + user, e); } return null; }
Example #8
Source File: SliceManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void applyRestore(byte[] payload, int user) { if (Binder.getCallingUid() != SYSTEM_UID) { throw new SecurityException("Caller must be system"); } if (payload == null) { Slog.w(TAG, "applyRestore: no payload to restore for user " + user); return; } //TODO: http://b/22388012 if (user != UserHandle.USER_SYSTEM) { Slog.w(TAG, "applyRestore: cannot restore policy for user " + user); return; } final ByteArrayInputStream bais = new ByteArrayInputStream(payload); try { XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); parser.setInput(bais, Encoding.UTF_8.name()); mPermissions.readRestore(parser); } catch (NumberFormatException | XmlPullParserException | IOException e) { Slog.w(TAG, "applyRestore: error reading payload", e); } }
Example #9
Source File: Main.java From WeChatLuckyMoney with Apache License 2.0 | 6 votes |
private String getFromXml(String xmlmsg, String node) throws XmlPullParserException, IOException { String xl = xmlmsg.substring(xmlmsg.indexOf("<msg>")); //nativeurl XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser pz = factory.newPullParser(); pz.setInput(new StringReader(xl)); int v = pz.getEventType(); String result = ""; while (v != XmlPullParser.END_DOCUMENT) { if (v == XmlPullParser.START_TAG) { if (pz.getName().equals(node)) { pz.nextToken(); result = pz.getText(); break; } } v = pz.next(); } return result; }
Example #10
Source File: WeChatHelper.java From WechatHook-Dusan with Apache License 2.0 | 6 votes |
public static String getFromXml(String xmlmsg, String node) throws XmlPullParserException, IOException { String xl = xmlmsg.substring(xmlmsg.indexOf("<msg>")); //nativeurl XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser pz = factory.newPullParser(); pz.setInput(new StringReader(xl)); int eventType = pz.getEventType(); String result = ""; while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (pz.getName().equals(node)) { pz.nextToken(); result = pz.getText(); break; } } eventType = pz.next(); } return result; }
Example #11
Source File: Dsmlv2Parser.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Creates a new instance of Dsmlv2Parser. * * @param storeMsgInBatchReq flag to set if the parsed requests should b stored * @throws XmlPullParserException if an error occurs during the initialization of the parser */ public Dsmlv2Parser( boolean storeMsgInBatchReq ) throws XmlPullParserException { this.storeMsgInBatchReq = storeMsgInBatchReq; this.grammar = new Dsmlv2Grammar(); this.container = new Dsmlv2Container( grammar.getLdapCodecService() ); this.container.setGrammar( grammar ); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware( true ); XmlPullParser xpp = factory.newPullParser(); container.setParser( xpp ); }
Example #12
Source File: TtmlDecoder.java From K-Sonic with MIT License | 5 votes |
public TtmlDecoder() { super("TtmlDecoder"); try { xmlParserFactory = XmlPullParserFactory.newInstance(); xmlParserFactory.setNamespaceAware(true); } catch (XmlPullParserException e) { throw new RuntimeException("Couldn't create XmlPullParserFactory instance", e); } }
Example #13
Source File: SsManifestParser.java From K-Sonic with MIT License | 5 votes |
public SsManifestParser() { try { xmlParserFactory = XmlPullParserFactory.newInstance(); } catch (XmlPullParserException e) { throw new RuntimeException("Couldn't create XmlPullParserFactory instance", e); } }
Example #14
Source File: TrustKitConfigurationTest.java From TrustKit-Android with MIT License | 5 votes |
private XmlPullParser parseXmlString(String xmlString) throws XmlPullParserException { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); String test = xmlString.replace("\n","").replace(" ",""); xpp.setInput(new StringReader(test)); return xpp; }
Example #15
Source File: UPnPDevice.java From android-upnp-discovery with MIT License | 5 votes |
private void xmlParse(String xml) { XmlParserCreator parserCreator = new XmlParserCreator() { @Override public XmlPullParser createParser() { try { return XmlPullParserFactory.newInstance().newPullParser(); } catch (Exception e) { throw new RuntimeException(e); } } }; GsonXml gsonXml = new GsonXmlBuilder() .setXmlParserCreator(parserCreator) .create(); DescriptionModel model = gsonXml.fromXml(xml, DescriptionModel.class); this.mFriendlyName = model.device.friendlyName; this.mDeviceType = model.device.deviceType; this.mPresentationURL = model.device.presentationURL; this.mSerialNumber = model.device.serialNumber; this.mModelName = model.device.modelName; this.mModelNumber = model.device.modelNumber; this.mModelURL = model.device.modelURL; this.mManufacturer = model.device.manufacturer; this.mManufacturerURL = model.device.manufacturerURL; this.mUDN = model.device.UDN; this.mURLBase = model.URLBase; }
Example #16
Source File: XMLParser.java From mConference-Framework with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void parse(Context context, URL url) throws XmlPullParserException, IOException{ InputStream inputStream = null; pullParserFactory = XmlPullParserFactory.newInstance(); parser = pullParserFactory.newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); db = new Database(context); sharedPreferences = context.getSharedPreferences(PREFERENCES_FILE_NAME, Context.MODE_PRIVATE); editor = sharedPreferences.edit(); Log.d("Parse", "parse"); if (SECOND_APPROACH) { fetchXML(url); } else { inputStream = context.getAssets().open("sampleXML.xml"); try { parser.setInput(inputStream, null); readXML(parser); } finally { inputStream.close(); } editor.putBoolean(PARSING_COMPLETE, true); } editor.apply(); }
Example #17
Source File: OrchestrationXmlTestRunListener.java From android-test with Apache License 2.0 | 5 votes |
/** Creates a report file and populates it with the report data from the completed tests. */ private void generateDocument(File reportDir, long elapsedTime) { String timestamp = getTimestamp(); OutputStream stream = null; try { stream = createOutputResultStream(reportDir); XmlSerializer serializer = XmlPullParserFactory.newInstance().newSerializer(); serializer.setOutput(stream, UTF_8); serializer.startDocument(UTF_8, null); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); // TODO: insert build info printTestResults(serializer, timestamp, elapsedTime); serializer.endDocument(); String msg = String.format( "XML test result file generated at %s. %s", getAbsoluteReportPath(), runResult.getTextSummary()); Log.i(LOG_TAG, msg); } catch (IOException | XmlPullParserException e) { Log.e(LOG_TAG, "Failed to generate report data", e); // TODO: consider throwing exception } finally { if (stream != null) { try { stream.close(); } catch (IOException ignored) { } } } }
Example #18
Source File: GoogleSuggestionSource.java From rxSuggestions with Apache License 2.0 | 5 votes |
@NonNull @Override public Flowable<SimpleSuggestionItem> getSuggestions(@NonNull String value) { return Flowable.fromCallable(() -> { final String suggestUrl = String.format(SUGGEST_URL_FORMAT, Util.prepareSearchTerm(value)); final URL url = new URL(suggestUrl); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.connect(); return httpURLConnection; }).flatMap(httpURLConnection -> Flowable.create(emitter -> { try (final InputStream inputStream = httpURLConnection.getInputStream()) { final XmlPullParser xmlParser = XmlPullParserFactory.newInstance().newPullParser(); xmlParser.setInput(inputStream, Util.extractEncoding(httpURLConnection.getContentType())); int eventType = xmlParser.getEventType(); while (isFlowableEmissionValid(emitter, eventType)) { // Perform back pressure aware iteration. boolean validEvent = eventType == START_TAG && xmlParser.getName().equalsIgnoreCase(SUGGESTION); if (validEvent) { final String suggestion = xmlParser.getAttributeValue(0); emitter.onNext(new SimpleSuggestionItem(suggestion)); } eventType = xmlParser.next(); } emitter.onComplete(); } finally { cancel(httpURLConnection); } emitter.setCancellable(() -> cancel(httpURLConnection)); }, BackpressureStrategy.LATEST)); }
Example #19
Source File: GradleDependencyEntity.java From freeline with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * xml解析为对象 * * @param text * @return */ public static GradleDependencyEntity parse(String text) { GradleDependencyEntity entity = new GradleDependencyEntity(); XmlPullParserFactory f = null; try { f = XmlPullParserFactory.newInstance(); f.setNamespaceAware(true); XmlPullParser xmlPullParser = f.newPullParser(); xmlPullParser.setInput(new InputStreamReader(new ByteArrayInputStream(text.getBytes()))); int eventType = xmlPullParser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_DOCUMENT) { } else if (eventType == XmlPullParser.START_TAG) { String name = xmlPullParser.getName(); if (name.equals("groupId")) { entity.setGroupId(xmlPullParser.nextText()); } else if (name.equals("artifactId")) { entity.setArtifactId(xmlPullParser.nextText()); } else if (name.equals("version")) { String version = xmlPullParser.nextText(); entity.setVersion(version); } else if (name.equals("lastUpdated")) { entity.setUpdateTime(xmlPullParser.nextText()); } } else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.TEXT) { } eventType = xmlPullParser.next(); } } catch (Exception e) { e.printStackTrace(); } return entity; }
Example #20
Source File: UPnPDevice.java From android-upnp-discovery with MIT License | 5 votes |
private void xmlParse(String xml) { XmlParserCreator parserCreator = new XmlParserCreator() { @Override public XmlPullParser createParser() { try { return XmlPullParserFactory.newInstance().newPullParser(); } catch (Exception e) { throw new RuntimeException(e); } } }; GsonXml gsonXml = new GsonXmlBuilder() .setXmlParserCreator(parserCreator) .create(); DescriptionModel model = gsonXml.fromXml(xml, DescriptionModel.class); this.mFriendlyName = model.device.friendlyName; this.mDeviceType = model.device.deviceType; this.mPresentationURL = model.device.presentationURL; this.mSerialNumber = model.device.serialNumber; this.mModelName = model.device.modelName; this.mModelNumber = model.device.modelNumber; this.mModelURL = model.device.modelURL; this.mManufacturer = model.device.manufacturer; this.mManufacturerURL = model.device.manufacturerURL; this.mUDN = model.device.UDN; this.mURLBase = model.URLBase; }
Example #21
Source File: EpubBook.java From BookyMcBookface with GNU General Public License v3.0 | 5 votes |
private static List<String> getRootFilesFromContainer(BufferedReader containerxml) { List<String> rootFiles = new ArrayList<>(); try { containerxml.mark(4); if ('\ufeff' != containerxml.read()) containerxml.reset(); // not the BOM marker XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(false); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(containerxml); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (xpp.getName().equals("rootfile")) { for (int i = 0; i < xpp.getAttributeCount(); i++) { if (xpp.getAttributeName(i).equals("full-path")) { rootFiles.add(xpp.getAttributeValue(i)); } } } } eventType = xpp.next(); } } catch (Exception e) { Log.e("BMBF", "Error parsing xml " + e, e); } return rootFiles; }
Example #22
Source File: ManifestPullParser.java From ic3 with Apache License 2.0 | 5 votes |
protected void loadClassesFromTextManifest(InputStream manifestIS) { try { XmlPullParserFactory xmlPullParserFactory = XmlPullParserFactory.newInstance(); xmlPullParserFactory.setNamespaceAware(true); XmlPullParser parser = xmlPullParserFactory.newPullParser(); parser.setInput(manifestIS, null); parse(parser); } catch (XmlPullParserException | IOException e) { e.printStackTrace(); throw new RuntimeException("Could not parse manifest file."); } }
Example #23
Source File: XMLResponseHandler.java From coursera-android with MIT License | 5 votes |
@Override public List<String> handleResponse(HttpResponse response) throws ClientProtocolException, IOException { try { // Create the Pull Parser XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser xpp = factory.newPullParser(); // Set the Parser's input to be the XML document in the HTTP Response xpp.setInput(new InputStreamReader(response.getEntity() .getContent())); // Get the first Parser event and start iterating over the XML document int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { startTag(xpp.getName()); } else if (eventType == XmlPullParser.END_TAG) { endTag(xpp.getName()); } else if (eventType == XmlPullParser.TEXT) { text(xpp.getText()); } eventType = xpp.next(); } return mResults; } catch (XmlPullParserException e) { } return null; }
Example #24
Source File: Dsmlv2Parser.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Creates a new instance of Dsmlv2Parser. * * @param grammar The grammar in use * @throws XmlPullParserException if an error occurs during the initialization of the parser */ public Dsmlv2Parser( Dsmlv2Grammar grammar ) throws XmlPullParserException { this.container = new Dsmlv2Container( grammar.getLdapCodecService() ); this.container.setGrammar( grammar ); this.grammar = grammar; XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware( true ); XmlPullParser xpp = factory.newPullParser(); container.setParser( xpp ); }
Example #25
Source File: TtmlParser.java From Exoplayer_VLC with Apache License 2.0 | 5 votes |
/** * @param strictParsing If true, {@link #parse(InputStream, String, long)} will throw a * {@link ParserException} if the stream contains invalid ttml. If false, the parser will * make a best effort to ignore minor errors in the stream. Note however that a * {@link ParserException} will still be thrown when this is not possible. */ public TtmlParser(boolean strictParsing) { this.strictParsing = strictParsing; try { xmlParserFactory = XmlPullParserFactory.newInstance(); } catch (XmlPullParserException e) { throw new RuntimeException("Couldn't create XmlPullParserFactory instance", e); } }
Example #26
Source File: MediaPresentationDescriptionParser.java From Exoplayer_VLC with Apache License 2.0 | 5 votes |
public MediaPresentationDescriptionParser() { try { xmlParserFactory = XmlPullParserFactory.newInstance(); } catch (XmlPullParserException e) { throw new RuntimeException("Couldn't create XmlPullParserFactory instance", e); } }
Example #27
Source File: Dsmlv2ResponseParser.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Creates a new instance of Dsmlv2ResponseParser. * * @param codec The Ldap Service to use * @throws XmlPullParserException if an error occurs while the initialization of the parser */ public Dsmlv2ResponseParser( LdapApiService codec ) throws XmlPullParserException { this.container = new Dsmlv2Container( codec ); this.container.setGrammar( Dsmlv2ResponseGrammar.getInstance() ); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware( true ); XmlPullParser xpp = factory.newPullParser(); container.setParser( xpp ); }
Example #28
Source File: GradleDependencyEntity.java From react-native-console with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * xml解析为对象 * * @param text * @return */ public static GradleDependencyEntity parse(String text) { GradleDependencyEntity entity = new GradleDependencyEntity(); XmlPullParserFactory f = null; try { f = XmlPullParserFactory.newInstance(); f.setNamespaceAware(true); XmlPullParser xmlPullParser = f.newPullParser(); xmlPullParser.setInput(new InputStreamReader(new ByteArrayInputStream(text.getBytes()))); int eventType = xmlPullParser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_DOCUMENT) { } else if (eventType == XmlPullParser.START_TAG) { String name = xmlPullParser.getName(); if (name.equals("groupId")) { entity.setGroupId(xmlPullParser.nextText()); } else if (name.equals("artifactId")) { entity.setArtifactId(xmlPullParser.nextText()); } else if (name.equals("version")) { String version = xmlPullParser.nextText(); entity.setVersion(version); } else if (name.equals("lastUpdated")) { entity.setUpdateTime(xmlPullParser.nextText()); } } else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.TEXT) { } eventType = xmlPullParser.next(); } } catch (Exception e) { e.printStackTrace(); } return entity; }
Example #29
Source File: DashManifestParser.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public DashManifestParser() { try { xmlParserFactory = XmlPullParserFactory.newInstance(); } catch (XmlPullParserException e) { throw new RuntimeException("Couldn't create XmlPullParserFactory instance", e); } }
Example #30
Source File: KmlLayer.java From android-maps-utils with Apache License 2.0 | 5 votes |
/** * Creates a new XmlPullParser to allow for the KML file to be parsed * * @param stream InputStream containing KML file * @return XmlPullParser containing the KML file * @throws XmlPullParserException if KML file cannot be parsed */ private static XmlPullParser createXmlParser(InputStream stream) throws XmlPullParserException { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser parser = factory.newPullParser(); parser.setInput(stream, null); return parser; }