Java Code Examples for org.xmlpull.v1.XmlPullParser#getEventType()
The following examples show how to use
org.xmlpull.v1.XmlPullParser#getEventType() .
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: XmlUtils.java From ticdesign with Apache License 2.0 | 8 votes |
/** * Read an ArrayList object from an XmlPullParser. The XML data could * previously have been generated by writeListXml(). The XmlPullParser * must be positioned <em>after</em> the tag that begins the list. * * @param parser The XmlPullParser from which to read the list data. * @param endTag Name of the tag that will end the list, usually "list". * @param name An array of one string, used to return the name attribute * of the list's tag. * * @return HashMap The newly generated list. * * @see #readListXml */ private static final ArrayList readThisListXml(XmlPullParser parser, String endTag, String[] name, ReadMapCallback callback) throws XmlPullParserException, java.io.IOException { ArrayList list = new ArrayList(); int eventType = parser.getEventType(); do { if (eventType == parser.START_TAG) { Object val = readThisValueXml(parser, name, callback); list.add(val); //System.out.println("Adding to list: " + val); } else if (eventType == parser.END_TAG) { if (parser.getName().equals(endTag)) { return list; } throw new XmlPullParserException( "Expected " + endTag + " end tag at: " + parser.getName()); } eventType = parser.next(); } while (eventType != parser.END_DOCUMENT); throw new XmlPullParserException( "Document ended before " + endTag + " end tag"); }
Example 2
Source File: Rss2Parser.java From PkRSS with Apache License 2.0 | 6 votes |
/** * Pulls an image URL from an encoded String. * * @param encoded The String which to extract an image URL from. * @return The first image URL found on the encoded String. May return an * empty String if none were found. */ private String pullImageLink(String encoded) { try { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(new StringReader(encoded)); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG && "img".equals(xpp.getName())) { int count = xpp.getAttributeCount(); for (int x = 0; x < count; x++) { if (xpp.getAttributeName(x).equalsIgnoreCase("src")) return pattern.matcher(xpp.getAttributeValue(x)).replaceAll(""); } } eventType = xpp.next(); } } catch (Exception e) { log(TAG, "Error pulling image link from description!\n" + e.getMessage(), Log.WARN); } return ""; }
Example 3
Source File: ECBXmlParser.java From Equate with GNU General Public License v3.0 | 6 votes |
private void skip(XmlPullParser parser) throws XmlPullParserException, IOException { if (parser.getEventType() != XmlPullParser.START_TAG){ throw new IllegalStateException(); } int depth = 1; while (depth != 0) { switch (parser.next()) { case XmlPullParser.END_TAG: depth--; break; case XmlPullParser.START_TAG: depth++; break; } } }
Example 4
Source File: KeyboardBuilder.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
private void parseKeyboard(final XmlPullParser parser) throws XmlPullParserException, IOException { if (DEBUG) startTag("<%s> %s", TAG_KEYBOARD, mParams.mId); while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { final int event = parser.next(); if (event == XmlPullParser.START_TAG) { final String tag = parser.getName(); if (TAG_KEYBOARD.equals(tag)) { parseKeyboardAttributes(parser); startKeyboard(); parseKeyboardContent(parser, false); return; } throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD); } } }
Example 5
Source File: DictParser.java From AndroidWeekly with Apache License 2.0 | 5 votes |
private void readDict(XmlPullParser parser) throws IOException, XmlPullParserException { parser.require(XmlPullParser.START_TAG, null, "dict"); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); switch (name) { case "key": dict.setKey(readText(parser)); break; case "ps": dict.addPs(readText(parser)); break; case "pron": dict.addPron(readText(parser)); break; case "pos": dict.addPos(readText(parser)); break; case "acceptation": dict.addAcceptation(readText(parser)); break; case "fy": dict.setFy(readText(parser)); break; case "sent": parseSent(parser); break; } } }
Example 6
Source File: XMLParser.java From mConference-Framework with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void readTalks(XmlPullParser parser) throws XmlPullParserException, IOException { parser.require(XmlPullParser.START_TAG, null, TALKS_TAG); ArrayList<TalkDetails> talks = new ArrayList<>(); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) continue; talks.add(readTalkItem(parser)); } db.addTalks(talks); parser.require(XmlPullParser.END_TAG, null, TALKS_TAG); }
Example 7
Source File: ImportFileUpdater.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Updates the passed import file into the equivalent 1.4 format. * * @param source the source import file * @param destination the destination import file */ public void updateImportFile(String source, String destination) { XmlPullParser reader = getReader(source); XMLWriter writer = getWriter(destination); this.shownWarning = false; try { // Start the documentation writer.startDocument(); // Start reading the document int eventType = reader.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { ImportFileUpdater.this.outputCurrentElement(reader, writer, new OutputChildren()); } eventType = reader.next(); } // End and close the document writer.endDocument(); writer.close(); } catch (Exception exception) { throw new AlfrescoRuntimeException("Unable to update import file.", exception); } }
Example 8
Source File: PluginManifestUtil.java From AndroidPlugin with MIT License | 5 votes |
private static void setAttrs(PlugInfo info, String manifestXML) throws XmlPullParserException, IOException { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser parser = factory.newPullParser(); parser.setInput(new StringReader(manifestXML)); int eventType = parser.getEventType(); String namespaceAndroid = null; do { switch (eventType) { case XmlPullParser.START_DOCUMENT: { break; } case XmlPullParser.START_TAG: { String tag = parser.getName(); if (tag.equals("manifest")) { namespaceAndroid = parser.getNamespace("android"); } else if ("activity".equals(parser.getName())) { addActivity(info, namespaceAndroid, parser); } else if ("receiver".equals(parser.getName())) { addReceiver(info, namespaceAndroid, parser); } else if ("service".equals(parser.getName())) { addService(info, namespaceAndroid, parser); } else if ("application".equals(parser.getName())) { parseApplicationInfo(info, namespaceAndroid, parser); } break; } case XmlPullParser.END_TAG: { break; } } eventType = parser.next(); } while (eventType != XmlPullParser.END_DOCUMENT); }
Example 9
Source File: WifiConfigStoreParser.java From WiFiKeyShare with GNU General Public License v3.0 | 5 votes |
private static List<WifiNetwork> readNetworkList(XmlPullParser parser) throws XmlPullParserException, IOException { List<WifiNetwork> result = new ArrayList<>(); parser.require(XmlPullParser.START_TAG, null, "NetworkList"); boolean doLoop = true; while (doLoop) { try { parser.next(); String tagName = parser.getName(); if (tagName == null) { tagName = ""; } doLoop = (!tagName.equalsIgnoreCase("NetworkList")); if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } if (tagName.equals("Network")) { WifiNetwork newWifi = readNetworkEntry(parser); if (newWifi.getSsid().length() != 0) { result.add(newWifi); } } else { skip(parser); } } catch (Exception e) { Log.e("LoadData.NetworkList", e.getMessage()); doLoop = false; } } return result; }
Example 10
Source File: SliceClientPermissions.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public synchronized void readFrom(XmlPullParser parser) throws IOException, XmlPullParserException { parser.next(); int depth = parser.getDepth(); while (parser.getDepth() >= depth) { if (parser.getEventType() == XmlPullParser.START_TAG && TAG_PATH.equals(parser.getName())) { mPaths.add(decodeSegments(parser.nextText())); } parser.next(); } }
Example 11
Source File: Model.java From ssj with GNU General Public License v3.0 | 4 votes |
private void parseTrainerFile(File file) throws XmlPullParserException, IOException, SSJException { XmlPullParser parser = Xml.newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); parser.setInput(new FileReader(file)); parser.next(); if (parser.getEventType() != XmlPullParser.START_TAG || !parser.getName().equalsIgnoreCase("trainer")) { Log.w("unknown or malformed trainer file"); return; } ArrayList<String> classNamesList = new ArrayList<>(); while (parser.next() != XmlPullParser.END_DOCUMENT) { //STREAM if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equalsIgnoreCase("streams")) { parser.nextTag(); //item if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equalsIgnoreCase("item")) { input_bytes = Integer.valueOf(parser.getAttributeValue(null, "byte")); input_dim = Integer.valueOf(parser.getAttributeValue(null, "dim")); input_sr = Float.valueOf(parser.getAttributeValue(null, "sr")); input_type = Cons.Type.valueOf(parser.getAttributeValue(null, "type")); } } // CLASS if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equalsIgnoreCase("classes")) { parser.nextTag(); while (parser.getName().equalsIgnoreCase("item")) { if (parser.getEventType() == XmlPullParser.START_TAG) { classNamesList.add(parser.getAttributeValue(null, "name")); } parser.nextTag(); } } //SELECT if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equalsIgnoreCase("select")) { parser.nextTag(); //item if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equalsIgnoreCase("item")) { int stream_id = Integer.valueOf(parser.getAttributeValue(null, "stream")); if (stream_id != 0) Log.w("multiple input streams not supported"); String[] select = parser.getAttributeValue(null, "select").split(" "); select_dimensions = new int[select.length]; for (int i = 0; i < select.length; i++) { select_dimensions[i] = Integer.valueOf(select[i]); } } } //MODEL if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equalsIgnoreCase("model")) { String expectedModel = parser.getAttributeValue(null, "create"); if(!_name.equals(expectedModel)) Log.w("trainer file demands a " + expectedModel + " model, we provide a " + _name + " model."); modelFileName = parser.getAttributeValue(null, "path"); modelOptionFileName = parser.getAttributeValue(null, "option"); if (modelFileName != null && modelFileName.endsWith("." + FileCons.FILE_EXTENSION_MODEL)) { modelFileName = modelFileName.replaceFirst("(.*)\\." + FileCons.FILE_EXTENSION_MODEL + "$", "$1"); } if (modelOptionFileName != null && modelOptionFileName.endsWith("." + FileCons.FILE_EXTENSION_OPTION)) { modelOptionFileName = modelOptionFileName.replaceFirst("(.*)\\." + FileCons.FILE_EXTENSION_OPTION + "$", "$1"); } } if (parser.getEventType() == XmlPullParser.END_TAG && parser.getName().equalsIgnoreCase("trainer")) break; } class_names = classNamesList.toArray(new String[0]); n_classes = class_names.length; }
Example 12
Source File: PullRealUrlParser.java From SprintNBA with Apache License 2.0 | 4 votes |
@Override public VideoRealUrl parse(InputStream is) throws Exception { VideoRealUrl real = new VideoRealUrl(); XmlPullParser parser = Xml.newPullParser(); //由android.util.Xml创建一个XmlPullParser实例 parser.setInput(is, "UTF-8"); int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_DOCUMENT: break; case XmlPullParser.START_TAG: if (parser.getName().equals("url")) { String urlbase = parser.nextText(); if ((urlbase.contains(".tc.qq.com")) && TextUtils.isEmpty(real.url)) { real.url = urlbase; LogUtils.i("url = " + real.url); } } else if (parser.getName().equals("fvkey")) { String vkey = parser.nextText(); LogUtils.i("vkey = " + vkey); real.fvkey = vkey; } else if (parser.getName().equals("vid")) { String vid = parser.nextText(); LogUtils.i("vid = " + vid); real.vid = vid; } else if (parser.getName().equals("fn")) { // 目前发现直接用{vid}.mp4 有部分不能播放,用fn下的可以 String fn = parser.nextText(); if (fn.endsWith(".mp4")) { LogUtils.i("fn = " + fn); real.fn = fn; } } break; case XmlPullParser.END_TAG: break; } eventType = parser.next(); } return real; }
Example 13
Source File: ApplicationListParser.java From Stringlate with MIT License | 4 votes |
private static ApplicationDetails readApplication(XmlPullParser parser) throws XmlPullParserException, IOException { String packageName, lastUpdated, name, description, iconUrl, sourceCodeUrl, webUrl, email; packageName = lastUpdated = name = description = iconUrl = sourceCodeUrl = webUrl = email = ""; parser.require(XmlPullParser.START_TAG, ns, "application"); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) continue; switch (parser.getName()) { case ID: packageName = readText(parser); break; case LAST_UPDATED: lastUpdated = readText(parser); break; case NAME: name = readText(parser); break; case DESCRIPTION: description = readText(parser); break; case WEB: webUrl = readText(parser); break; case ICON: if (fdroidIconPath != null) { iconUrl = fdroidIconPath + readText(parser); } break; case ICON_URL: iconUrl = readText(parser); break; case SOURCE_URL: sourceCodeUrl = readText(parser); break; case MAIL: email = readText(parser); break; default: skip(parser); break; } } parser.require(XmlPullParser.END_TAG, ns, "application"); return new ApplicationDetails(packageName, lastUpdated, name, description, iconUrl, sourceCodeUrl, webUrl, email); }
Example 14
Source File: JobStore.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private List<JobStatus> readJobMapImpl(FileInputStream fis, boolean rtcIsGood) throws XmlPullParserException, IOException { XmlPullParser parser = Xml.newPullParser(); parser.setInput(fis, StandardCharsets.UTF_8.name()); int eventType = parser.getEventType(); while (eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_DOCUMENT) { eventType = parser.next(); Slog.d(TAG, "Start tag: " + parser.getName()); } if (eventType == XmlPullParser.END_DOCUMENT) { if (DEBUG) { Slog.d(TAG, "No persisted jobs."); } return null; } String tagName = parser.getName(); if ("job-info".equals(tagName)) { final List<JobStatus> jobs = new ArrayList<JobStatus>(); // Read in version info. try { int version = Integer.parseInt(parser.getAttributeValue(null, "version")); if (version != JOBS_FILE_VERSION) { Slog.d(TAG, "Invalid version number, aborting jobs file read."); return null; } } catch (NumberFormatException e) { Slog.e(TAG, "Invalid version number, aborting jobs file read."); return null; } eventType = parser.next(); do { // Read each <job/> if (eventType == XmlPullParser.START_TAG) { tagName = parser.getName(); // Start reading job. if ("job".equals(tagName)) { JobStatus persistedJob = restoreJobFromXml(rtcIsGood, parser); if (persistedJob != null) { if (DEBUG) { Slog.d(TAG, "Read out " + persistedJob); } jobs.add(persistedJob); } else { Slog.d(TAG, "Error reading job from file."); } } } eventType = parser.next(); } while (eventType != XmlPullParser.END_DOCUMENT); return jobs; } return null; }
Example 15
Source File: TrustKitConfigurationParser.java From TrustKit-Android with MIT License | 4 votes |
/** * Parse an XML TrustKit / Network Security policy and return the corresponding * {@link TrustKitConfiguration}. */ @NonNull public static TrustKitConfiguration fromXmlPolicy( @NonNull Context context, @NonNull XmlPullParser parser ) throws XmlPullParserException, IOException, CertificateException { // Handle nested domain config tags // https://developer.android.com/training/articles/security-config.html#ConfigInheritance List<DomainPinningPolicy.Builder> builderList = new ArrayList<>(); DebugOverridesTag debugOverridesTag = null; int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if ("domain-config".equals(parser.getName())) { builderList.addAll(readDomainConfig(parser, null)); } else if ("debug-overrides".equals(parser.getName())) { // The debug-overrides option is global and not tied to a specific domain debugOverridesTag = readDebugOverrides(context, parser); } } eventType = parser.next(); } // Finally, store the result of the parsed policy in our configuration object TrustKitConfiguration config; HashSet<DomainPinningPolicy> domainConfigSet = new HashSet<>(); for (DomainPinningPolicy.Builder builder : builderList) { DomainPinningPolicy policy = builder.build(); if (policy != null) { domainConfigSet.add(policy); } } if (debugOverridesTag != null) { config = new TrustKitConfiguration( domainConfigSet, debugOverridesTag.overridePins, debugOverridesTag.debugCaCertificates ); } else { config = new TrustKitConfiguration(domainConfigSet); } return config; }
Example 16
Source File: IconPackHelper.java From Hangar with GNU General Public License v3.0 | 4 votes |
private static void loadResourcesFromXmlParser(XmlPullParser parser, Map<String, String> iconPackResources) throws XmlPullParserException, IOException { int eventType = parser.getEventType(); do { if (eventType != XmlPullParser.START_TAG) { continue; } if (!parser.getName().equalsIgnoreCase("item")) { continue; } String component = parser.getAttributeValue(null, "component"); String drawable = parser.getAttributeValue(null, "drawable"); // Validate component/drawable exist if (TextUtils.isEmpty(component) || TextUtils.isEmpty(drawable)) { continue; } // Validate format/length of component if (!component.startsWith("ComponentInfo{") || !component.endsWith("}") || component.length() < 16) { continue; } // Sanitize stored value component = component.substring(14, component.length() - 1).toLowerCase(Locale.getDefault()); ComponentName name; if (!component.contains("/")) { // Package icon reference iconPackResources.put(component, drawable); } else { name = ComponentName.unflattenFromString(component); if (name != null) { iconPackResources.put(name.getPackageName(), drawable); iconPackResources.put(name.getClassName(), drawable); } } } while ((eventType = parser.next()) != XmlPullParser.END_DOCUMENT); }
Example 17
Source File: ComponentDescription.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * */ private ComponentDescription(Bundle b, XmlPullParser p) throws IOException, XmlPullParserException { this.bundle = b; if (SCR_NAMESPACE_V1_3_0_URI.equals(p.getNamespace())) { scrNSminor = 3; } else if (SCR_NAMESPACE_V1_2_0_URI.equals(p.getNamespace())) { scrNSminor = 2; } else if (SCR_NAMESPACE_V1_1_0_URI.equals(p.getNamespace())) { scrNSminor = 1; } parseAttributes(p); for (int e = p.getEventType(); e != XmlPullParser.END_TAG; e = p.getEventType()) { if (!findNextStartTag(p, false)) { if (p.getEventType() == XmlPullParser.END_DOCUMENT) { throw new IllegalXMLException("Component \"" + componentName + "\" lacks end-tag", p); } break; } String tag = p.getName(); Activator.logDebug("Found component sub-element: " + tag); if ("implementation".equals(tag)) { parseImplementation(p); } else if ("property".equals(tag)) { parseProperty(p); } else if ("properties".equals(tag)) { parseProperties(p); } else if ("service".equals(tag)) { parseService(p); } else if ("reference".equals(tag)) { parseReference(p); } else { Activator.logDebug("Skip unknown component sub-element: " + tag); skip(p); } } if (implementation == null) { throw new IllegalXMLException("Component \"" + componentName + "\" lacks implementation-tag", p); } if (services == null && immediateSet && !immediate) { throw new IllegalXMLException("Attribute immediate in component-tag must "+ "be set to \"true\" when component-factory is "+ "not set and we do not have a service element", p); } }
Example 18
Source File: CumulusXmlParser.java From CumulusTV with MIT License | 4 votes |
private static Channel parseChannel(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException { String id = null; boolean repeatPrograms = false; for (int i = 0; i < parser.getAttributeCount(); ++i) { String attr = parser.getAttributeName(i); String value = parser.getAttributeValue(i); if (ATTR_ID.equalsIgnoreCase(attr)) { id = value; } else if (ATTR_REPEAT_PROGRAMS.equalsIgnoreCase(attr)) { repeatPrograms = "TRUE".equalsIgnoreCase(value); } } String displayName = null; String displayNumber = null; XmlTvIcon icon = null; XmlTvAppLink appLink = null; Advertisement advertisement = null; while (parser.next() != XmlPullParser.END_DOCUMENT) { if (parser.getEventType() == XmlPullParser.START_TAG) { if (TAG_DISPLAY_NAME.equalsIgnoreCase(parser.getName()) && displayName == null) { displayName = parser.nextText(); } else if (TAG_DISPLAY_NUMBER.equalsIgnoreCase(parser.getName()) && displayNumber == null) { displayNumber = parser.nextText(); } else if (TAG_ICON.equalsIgnoreCase(parser.getName()) && icon == null) { icon = parseIcon(parser); } else if (TAG_APP_LINK.equalsIgnoreCase(parser.getName()) && appLink == null) { appLink = parseAppLink(parser); } else if (TAG_AD.equalsIgnoreCase(parser.getName()) && advertisement == null) { advertisement = parseAd(parser, TAG_CHANNEL); } } else if (TAG_CHANNEL.equalsIgnoreCase(parser.getName()) && parser.getEventType() == XmlPullParser.END_TAG) { break; } } if (TextUtils.isEmpty(id) || TextUtils.isEmpty(displayName)) { throw new IllegalArgumentException("id and display-name can not be null."); } // Developers should assign original network ID in the right way not using the fake ID. InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setRepeatable(repeatPrograms); Channel.Builder builder = new Channel.Builder() .setDisplayName(displayName) .setDisplayNumber(displayNumber) .setOriginalNetworkId(id.hashCode()) .setInternalProviderData(internalProviderData) .setTransportStreamId(0) .setServiceId(0); if (icon != null) { builder.setChannelLogo(icon.src); } if (appLink != null) { builder.setAppLinkColor(appLink.color) .setAppLinkIconUri(appLink.icon.src) .setAppLinkIntentUri(appLink.intentUri) .setAppLinkPosterArtUri(appLink.posterUri) .setAppLinkText(appLink.text); } if (advertisement != null) { List<Advertisement> advertisements = new ArrayList<>(1); advertisements.add(advertisement); internalProviderData.setAds(advertisements); builder.setInternalProviderData(internalProviderData); } return builder.build(); }
Example 19
Source File: DashManifestParser.java From MediaSDK with Apache License 2.0 | 4 votes |
/** * Parses an event object. * * @param xpp The current xml parser. * @param scratchOutputStream A {@link ByteArrayOutputStream} that's used when parsing the object. * @return The serialized byte array. * @throws XmlPullParserException If there is any error parsing this node. * @throws IOException If there is any error reading from the underlying input stream. */ protected byte[] parseEventObject(XmlPullParser xpp, ByteArrayOutputStream scratchOutputStream) throws XmlPullParserException, IOException { scratchOutputStream.reset(); XmlSerializer xmlSerializer = Xml.newSerializer(); xmlSerializer.setOutput(scratchOutputStream, C.UTF8_NAME); // Start reading everything between <Event> and </Event>, and serialize them into an Xml // byte array. xpp.nextToken(); while (!XmlPullParserUtil.isEndTag(xpp, "Event")) { switch (xpp.getEventType()) { case (XmlPullParser.START_DOCUMENT): xmlSerializer.startDocument(null, false); break; case (XmlPullParser.END_DOCUMENT): xmlSerializer.endDocument(); break; case (XmlPullParser.START_TAG): xmlSerializer.startTag(xpp.getNamespace(), xpp.getName()); for (int i = 0; i < xpp.getAttributeCount(); i++) { xmlSerializer.attribute(xpp.getAttributeNamespace(i), xpp.getAttributeName(i), xpp.getAttributeValue(i)); } break; case (XmlPullParser.END_TAG): xmlSerializer.endTag(xpp.getNamespace(), xpp.getName()); break; case (XmlPullParser.TEXT): xmlSerializer.text(xpp.getText()); break; case (XmlPullParser.CDSECT): xmlSerializer.cdsect(xpp.getText()); break; case (XmlPullParser.ENTITY_REF): xmlSerializer.entityRef(xpp.getText()); break; case (XmlPullParser.IGNORABLE_WHITESPACE): xmlSerializer.ignorableWhitespace(xpp.getText()); break; case (XmlPullParser.PROCESSING_INSTRUCTION): xmlSerializer.processingInstruction(xpp.getText()); break; case (XmlPullParser.COMMENT): xmlSerializer.comment(xpp.getText()); break; case (XmlPullParser.DOCDECL): xmlSerializer.docdecl(xpp.getText()); break; default: // fall out } xpp.nextToken(); } xmlSerializer.flush(); return scratchOutputStream.toByteArray(); }
Example 20
Source File: XmlPullParserUtil.java From K-Sonic with MIT License | 2 votes |
/** * Returns whether the current event is a start tag. * * @param xpp The {@link XmlPullParser} to query. * @return Whether the current event is a start tag. * @throws XmlPullParserException If an error occurs querying the parser. */ public static boolean isStartTag(XmlPullParser xpp) throws XmlPullParserException { return xpp.getEventType() == XmlPullParser.START_TAG; }