Java Code Examples for org.xmlpull.v1.XmlPullParser#getName()
The following examples show how to use
org.xmlpull.v1.XmlPullParser#getName() .
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: GPXParser.java From android-gpx-parser with Apache License 2.0 | 6 votes |
private TrackSegment readSegment(XmlPullParser parser) throws IOException, XmlPullParserException { List<TrackPoint> points = new ArrayList<>(); parser.require(XmlPullParser.START_TAG, namespace, TAG_SEGMENT); while (loopMustContinue(parser.next())) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); if (TAG_TRACK_POINT.equals(name)) { points.add(readTrackPoint(parser)); } else { skip(parser); } } parser.require(XmlPullParser.END_TAG, namespace, TAG_SEGMENT); return new TrackSegment.Builder() .setTrackPoints(points) .build(); }
Example 2
Source File: XmlUtils.java From HeadsUp with GNU General Public License v2.0 | 6 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 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 == XmlPullParser.START_TAG) { Object val = readThisValueXml(parser, name, callback); list.add(val); //System.out.println("Adding to list: " + val); } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(endTag)) { return list; } throw new XmlPullParserException( "Expected " + endTag + " end tag at: " + parser.getName()); } eventType = parser.next(); } while (eventType != XmlPullParser.END_DOCUMENT); throw new XmlPullParserException( "Document ended before " + endTag + " end tag"); }
Example 3
Source File: XmlUtils.java From cwac-netsecurity with Apache License 2.0 | 6 votes |
/** * Read a HashMap object from an XmlPullParser. The XML data could * previously have been generated by writeMapXml(). The XmlPullParser * must be positioned <em>after</em> the tag that begins the map. * * @param parser The XmlPullParser from which to read the map data. * @param endTag Name of the tag that will end the map, usually "map". * @param name An array of one string, used to return the name attribute * of the map's tag. * * @return HashMap The newly generated map. * * @see # readMapXml * @hide */ public static final HashMap<String, ?> readThisMapXml(XmlPullParser parser, String endTag, String[] name, ReadMapCallback callback) throws XmlPullParserException, IOException { HashMap<String, Object> map = new HashMap<String, Object>(); int eventType = parser.getEventType(); do { if (eventType == parser.START_TAG) { Object val = readThisValueXml(parser, name, callback, false); map.put(name[0], val); } else if (eventType == parser.END_TAG) { if (parser.getName().equals(endTag)) { return map; } 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 4
Source File: XmlUtils.java From J2ME-Loader with Apache License 2.0 | 6 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, boolean arrayMap) 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, arrayMap); 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 5
Source File: XmlUtils.java From AcDisplay with GNU General Public License v2.0 | 6 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 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 == XmlPullParser.START_TAG) { Object val = readThisValueXml(parser, name, callback); list.add(val); //System.out.println("Adding to list: " + val); } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(endTag)) { return list; } throw new XmlPullParserException( "Expected " + endTag + " end tag at: " + parser.getName()); } eventType = parser.next(); } while (eventType != XmlPullParser.END_DOCUMENT); throw new XmlPullParserException( "Document ended before " + endTag + " end tag"); }
Example 6
Source File: SettingsState.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
private void parseStateLocked(XmlPullParser parser) throws IOException, XmlPullParserException { final int outerDepth = parser.getDepth(); int type; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } String tagName = parser.getName(); if (tagName.equals(TAG_SETTINGS)) { parseSettingsLocked(parser); } } }
Example 7
Source File: KeyboardBuilder.java From Indic-Keyboard 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 8
Source File: Controller.java From ampdroid with MIT License | 5 votes |
private void parseArtistsXML(XmlPullParser parser) throws XmlPullParserException, IOException { this.artists = new ArrayList<Artist>(); int eventType = parser.getEventType(); Artist currentArtist = null; while (eventType != XmlPullParser.END_DOCUMENT) { String name = null; switch (eventType) { case XmlPullParser.START_TAG: name = parser.getName(); if (name.equals("artist")) { currentArtist = new Artist(); currentArtist.setId(Integer.parseInt((parser.getAttributeValue(null, "id")))); } else if (currentArtist != null) { if (name.equals("name")) { currentArtist.setName(parser.nextText()); } else if (name.equals("albums")) { currentArtist.setAlbums(Integer.parseInt(parser.nextText())); } else if (name.equals("songs")) { currentArtist.setSongs(Integer.parseInt(parser.nextText())); } } break; case XmlPullParser.END_TAG: name = parser.getName(); if (name.equalsIgnoreCase("artist") && currentArtist != null) { this.artists.add(currentArtist); this.progress++; } } eventType = parser.next(); } Log.d("artists:", this.artists.toString()); }
Example 9
Source File: ManifestPullParser.java From ic3 with Apache License 2.0 | 5 votes |
private boolean handleEndTag(XmlPullParser parser) { String tagName = parser.getName(); if (skipToEndTag != null) { if (skipToEndTag.equals(tagName)) { skipToEndTag = null; } return true; } if (tagName.equals(ACTIVITY)) { return handleActivityEnd(parser); } if (tagName.equals(ACTIVITY_ALIAS)) { return handleActivityAliasEnd(parser); } if (tagName.equals(SERVICE)) { return handleServiceEnd(parser); } if (tagName.equals(RECEIVER)) { return handleReceiverEnd(parser); } if (tagName.equals(INTENT_FILTER)) { return handleIntentFilterEnd(parser); } if (tagName.equals(PROVIDER)) { return handleProviderEnd(parser); } return true; }
Example 10
Source File: KeyChainSnapshotDeserializer.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static WrappedApplicationKey readWrappedApplicationKey(XmlPullParser parser) throws IOException, XmlPullParserException, KeyChainSnapshotParserException { parser.require(XmlPullParser.START_TAG, NAMESPACE, TAG_APPLICATION_KEY); WrappedApplicationKey.Builder builder = new WrappedApplicationKey.Builder(); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); switch (name) { case TAG_ALIAS: builder.setAlias(readStringTag(parser, TAG_ALIAS)); break; case TAG_KEY_MATERIAL: builder.setEncryptedKeyMaterial(readBlobTag(parser, TAG_KEY_MATERIAL)); break; default: throw new KeyChainSnapshotParserException(String.format( Locale.US, "Unexpected tag %s in wrappedApplicationKey", name)); } } parser.require(XmlPullParser.END_TAG, NAMESPACE, TAG_APPLICATION_KEY); try { return builder.build(); } catch (NullPointerException e) { throw new KeyChainSnapshotParserException("Failed to build WrappedApplicationKey", e); } }
Example 11
Source File: AnimationUtils.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static LayoutAnimationController createLayoutAnimationFromXml(Context c, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { LayoutAnimationController controller = null; int type; int depth = parser.getDepth(); while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); if ("layoutAnimation".equals(name)) { controller = new LayoutAnimationController(c, attrs); } else if ("gridLayoutAnimation".equals(name)) { controller = new GridLayoutAnimationController(c, attrs); } else { throw new RuntimeException("Unknown layout animation name: " + name); } } return controller; }
Example 12
Source File: PluginManifestUtil.java From AndroidPlugin with MIT License | 5 votes |
private static void addReceiver(PlugInfo info, String namespace, XmlPullParser parser) throws XmlPullParserException, IOException { int eventType = parser.getEventType(); String receiverName = parser.getAttributeValue(namespace, "name"); String packageName = info.getPackageInfo().packageName; receiverName = getName(receiverName, packageName); ResolveInfo receiver = new ResolveInfo(); // 此时的activityInfo 表示 receiverInfo receiver.activityInfo = info.findReceiverByClassName(receiverName); do { switch (eventType) { case XmlPullParser.START_TAG: { String tag = parser.getName(); if ("intent-filter".equals(tag)) { if (receiver.filter == null) { receiver.filter = new IntentFilter(); } } else if ("action".equals(tag)) { String actionName = parser.getAttributeValue(namespace, "name"); receiver.filter.addAction(actionName); } else if ("category".equals(tag)) { String category = parser.getAttributeValue(namespace, "name"); receiver.filter.addCategory(category); } else if ("data".equals(tag)) { // TODO parse data } break; } } eventType = parser.next(); } while (!"receiver".equals(parser.getName())); // info.addReceiver(receiver); }
Example 13
Source File: PullSOAPActionProcessorImpl.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
protected ActionException readFaultElement(XmlPullParser xpp) throws Exception { // We're in the "Fault" tag String errorCode = null; String errorDescription = null; XmlPullParserUtils.searchTag(xpp, "UPnPError"); int event; do { event = xpp.next(); if (event == XmlPullParser.START_TAG) { String tag = xpp.getName(); if (tag.equals("errorCode")) { errorCode = xpp.nextText(); } else if (tag.equals("errorDescription")) { errorDescription = xpp.nextText(); } } } while (event != XmlPullParser.END_DOCUMENT && (event != XmlPullParser.END_TAG || !xpp.getName().equals("UPnPError"))); if (errorCode != null) { try { int numericCode = Integer.valueOf(errorCode); ErrorCode standardErrorCode = ErrorCode.getByCode(numericCode); if (standardErrorCode != null) { log.fine("Reading fault element: " + standardErrorCode.getCode() + " - " + errorDescription); return new ActionException(standardErrorCode, errorDescription, false); } else { log.fine("Reading fault element: " + numericCode + " - " + errorDescription); return new ActionException(numericCode, errorDescription); } } catch (NumberFormatException ex) { throw new RuntimeException("Error code was not a number"); } } throw new RuntimeException("Received fault element but no error code"); }
Example 14
Source File: ConfigXmlParser.java From keemob with MIT License | 5 votes |
public void handleEndTag(XmlPullParser xml) { String strNode = xml.getName(); if (strNode.equals("feature")) { pluginEntries.add(new PluginEntry(service, pluginClass, onload)); service = ""; pluginClass = ""; insideFeature = false; onload = false; } }
Example 15
Source File: ConfigXmlParser.java From app-icon with MIT License | 5 votes |
public void handleStartTag(XmlPullParser xml) { String strNode = xml.getName(); if (strNode.equals("feature")) { //Check for supported feature sets aka. plugins (Accelerometer, Geolocation, etc) //Set the bit for reading params insideFeature = true; service = xml.getAttributeValue(null, "name"); } else if (insideFeature && strNode.equals("param")) { paramType = xml.getAttributeValue(null, "name"); if (paramType.equals("service")) // check if it is using the older service param service = xml.getAttributeValue(null, "value"); else if (paramType.equals("package") || paramType.equals("android-package")) pluginClass = xml.getAttributeValue(null,"value"); else if (paramType.equals("onload")) onload = "true".equals(xml.getAttributeValue(null, "value")); } else if (strNode.equals("preference")) { String name = xml.getAttributeValue(null, "name").toLowerCase(Locale.ENGLISH); String value = xml.getAttributeValue(null, "value"); prefs.set(name, value); } else if (strNode.equals("content")) { String src = xml.getAttributeValue(null, "src"); if (src != null) { setStartUrl(src); } } }
Example 16
Source File: MenuInflater.java From Libraries-for-Android-Developers with MIT License | 4 votes |
/** * Called internally to fill the given menu. If a sub menu is seen, it will * call this recursively. */ private void parseMenu(XmlPullParser parser, AttributeSet attrs, Menu menu) throws XmlPullParserException, IOException { MenuState menuState = new MenuState(menu); int eventType = parser.getEventType(); String tagName; boolean lookingForEndOfUnknownTag = false; String unknownTagName = null; // This loop will skip to the menu start tag do { if (eventType == XmlPullParser.START_TAG) { tagName = parser.getName(); if (tagName.equals(XML_MENU)) { // Go to next tag eventType = parser.next(); break; } throw new RuntimeException("Expecting menu, got " + tagName); } eventType = parser.next(); } while (eventType != XmlPullParser.END_DOCUMENT); boolean reachedEndOfMenu = false; while (!reachedEndOfMenu) { switch (eventType) { case XmlPullParser.START_TAG: if (lookingForEndOfUnknownTag) { break; } tagName = parser.getName(); if (tagName.equals(XML_GROUP)) { menuState.readGroup(attrs); } else if (tagName.equals(XML_ITEM)) { menuState.readItem(attrs); } else if (tagName.equals(XML_MENU)) { // A menu start tag denotes a submenu for an item SubMenu subMenu = menuState.addSubMenuItem(); // Parse the submenu into returned SubMenu parseMenu(parser, attrs, subMenu); } else { lookingForEndOfUnknownTag = true; unknownTagName = tagName; } break; case XmlPullParser.END_TAG: tagName = parser.getName(); if (lookingForEndOfUnknownTag && tagName.equals(unknownTagName)) { lookingForEndOfUnknownTag = false; unknownTagName = null; } else if (tagName.equals(XML_GROUP)) { menuState.resetGroup(); } else if (tagName.equals(XML_ITEM)) { // Add the item if it hasn't been added (if the item was // a submenu, it would have been added already) if (!menuState.hasAddedItem()) { if (menuState.itemActionProvider != null && menuState.itemActionProvider.hasSubMenu()) { menuState.addSubMenuItem(); } else { menuState.addItem(); } } } else if (tagName.equals(XML_MENU)) { reachedEndOfMenu = true; } break; case XmlPullParser.END_DOCUMENT: throw new RuntimeException("Unexpected end of document"); } eventType = parser.next(); } }
Example 17
Source File: ShortcutPackage.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public static ShortcutPackage loadFromXml(ShortcutService s, ShortcutUser shortcutUser, XmlPullParser parser, boolean fromBackup) throws IOException, XmlPullParserException { final String packageName = ShortcutService.parseStringAttribute(parser, ATTR_NAME); final ShortcutPackage ret = new ShortcutPackage(shortcutUser, shortcutUser.getUserId(), packageName); ret.mApiCallCount = ShortcutService.parseIntAttribute(parser, ATTR_CALL_COUNT); ret.mLastResetTime = ShortcutService.parseLongAttribute(parser, ATTR_LAST_RESET); final int outerDepth = parser.getDepth(); int type; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type != XmlPullParser.START_TAG) { continue; } final int depth = parser.getDepth(); final String tag = parser.getName(); if (depth == outerDepth + 1) { switch (tag) { case ShortcutPackageInfo.TAG_ROOT: ret.getPackageInfo().loadFromXml(parser, fromBackup); continue; case TAG_SHORTCUT: final ShortcutInfo si = parseShortcut(parser, packageName, shortcutUser.getUserId(), fromBackup); // Don't use addShortcut(), we don't need to save the icon. ret.mShortcuts.put(si.getId(), si); continue; } } ShortcutService.warnForInvalidTag(depth, tag); } return ret; }
Example 18
Source File: DBHelper.java From fdroidclient with GNU General Public License v3.0 | 4 votes |
/** * Parse {@code additional_repos.xml} into a list of items. Walk through * all TEXT pieces of the xml file and put them into a single list of repo * elements. Each repo is defined as eight elements in that list. * {@code additional_repos.xml} has seven elements per repo because it is * not allowed to set the priority since that would give it the power to * override {@code default_repos.xml}. */ public static List<String> parseAdditionalReposXml(File additionalReposFile) throws IOException, XmlPullParserException { List<String> repoItems = new LinkedList<>(); InputStream xmlInputStream = new FileInputStream(additionalReposFile); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser parser = factory.newPullParser(); parser.setInput(xmlInputStream, "UTF-8"); int eventType = parser.getEventType(); boolean isItem = false; while (eventType != XmlPullParser.END_DOCUMENT) { String tagname = parser.getName(); switch (eventType) { case XmlPullParser.START_TAG: if ("item".equals(tagname)) { isItem = true; } break; case XmlPullParser.END_TAG: isItem = false; break; case XmlPullParser.TEXT: if (isItem) { repoItems.add(parser.getText()); } break; } eventType = parser.next(); } xmlInputStream.close(); final int priorityIndex = 5; for (int i = priorityIndex; i < repoItems.size(); i += REPO_XML_ITEM_COUNT) { repoItems.add(i, "0"); } if (repoItems.size() % REPO_XML_ITEM_COUNT == 0) { return repoItems; } Log.e(TAG, "Ignoring " + additionalReposFile + ", wrong number of items: " + repoItems.size() + " % " + (REPO_XML_ITEM_COUNT - 1) + " != 0"); return new LinkedList<>(); }
Example 19
Source File: GPXParser.java From android-gpx-parser with Apache License 2.0 | 4 votes |
private Route readRoute(XmlPullParser parser) throws IOException, XmlPullParserException { List<RoutePoint> points = new ArrayList<>(); parser.require(XmlPullParser.START_TAG, namespace, TAG_ROUTE); Route.Builder routeBuilder = new Route.Builder(); while (loopMustContinue(parser.next())) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); switch (name) { case TAG_ROUTE_POINT: points.add(readRoutePoint(parser)); break; case TAG_NAME: routeBuilder.setRouteName(readName(parser)); break; case TAG_DESC: routeBuilder.setRouteDesc(readDesc(parser)); break; case TAG_CMT: routeBuilder.setRouteCmt(readCmt(parser)); break; case TAG_SRC: routeBuilder.setRouteSrc(readString(parser, TAG_SRC)); break; case TAG_LINK: routeBuilder.setRouteLink(readLink(parser)); break; case TAG_NUMBER: routeBuilder.setRouteNumber(readNumber(parser)); break; case TAG_TYPE: routeBuilder.setRouteType(readString(parser, TAG_TYPE)); break; default: skip(parser); break; } } parser.require(XmlPullParser.END_TAG, namespace, TAG_ROUTE); return routeBuilder .setRoutePoints(points) .build(); }
Example 20
Source File: XmlToJson.java From WechatEnhancement with GNU General Public License v3.0 | 4 votes |
private void readTags(Tag parent, XmlPullParser xpp) { try { int eventType; do { eventType = xpp.next(); if (eventType == XmlPullParser.START_TAG) { String tagName = xpp.getName(); String path = parent.getPath() + "/" + tagName; boolean skipTag = mSkippedTags.contains(path); Tag child = new Tag(path, tagName); if (!skipTag) { parent.addChild(child); } // Attributes are taken into account as key/values in the child int attrCount = xpp.getAttributeCount(); for (int i = 0; i < attrCount; ++i) { String attrName = xpp.getAttributeName(i); String attrValue = xpp.getAttributeValue(i); String attrPath = parent.getPath() + "/" + child.getName() + "/" + attrName; // Skip Attributes if (mSkippedAttributes.contains(attrPath)) { continue; } attrName = getAttributeNameReplacement(attrPath, attrName); Tag attribute = new Tag(attrPath, attrName); attribute.setContent(attrValue); child.addChild(attribute); } readTags(child, xpp); } else if (eventType == XmlPullParser.TEXT) { String text = xpp.getText(); parent.setContent(text); } else if (eventType == XmlPullParser.END_TAG) { return; } else { Log.i(TAG, "unknown xml eventType " + eventType); } } while (eventType != XmlPullParser.END_DOCUMENT); } catch (XmlPullParserException | IOException | NullPointerException e) { e.printStackTrace(); } }