Java Code Examples for org.xmlpull.v1.XmlPullParser#TEXT
The following examples show how to use
org.xmlpull.v1.XmlPullParser#TEXT .
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: FtcSongXml.java From FtcSamples with MIT License | 6 votes |
/** * This method parses the song section in the XML file. The song section starts with a section tag and * contains a sequence of notated notes separated by commas. * * @param song specifies the song object that the section belongs to. * @throws XmlPullParserException * @throws IOException */ private void parseSection(TrcSong song) throws XmlPullParserException, IOException { final String funcName = "parseSection"; if (debugEnabled) { dbgTrace.traceEnter(funcName, TrcDbgTrace.TraceLevel.FUNC, "song=%s", song.toString()); } parser.require(XmlPullParser.START_TAG, null, "section"); String name = parser.getAttributeValue(null, "name"); String notation = ""; while (parser.next() == XmlPullParser.TEXT) { notation += parser.getText(); } song.addSection(name, notation); parser.require(XmlPullParser.END_TAG, null, "section"); if (debugEnabled) { dbgTrace.traceExit(funcName, TrcDbgTrace.TraceLevel.FUNC, "! (%s=%s)", name, notation); } }
Example 2
Source File: SvgToPath.java From UltimateAndroid with Apache License 2.0 | 6 votes |
void processSvg() throws XmlPullParserException, IOException { int eventType = atts.getEventType(); do { switch (eventType) { case XmlPullParser.START_DOCUMENT: case XmlPullParser.END_DOCUMENT: case XmlPullParser.TEXT: // no op break; case XmlPullParser.START_TAG: startElement(); break; case XmlPullParser.END_TAG: endElement(); break; } eventType = atts.next(); } while (eventType != XmlPullParser.END_DOCUMENT); }
Example 3
Source File: XmlParser.java From SimpleNews with Apache License 2.0 | 5 votes |
/** * Parse changeLogText node * * @param parser * @throws Exception */ private static Feed readFeed(XmlPullParser parser) throws XmlPullParserException, IOException { Feed feed = null; if (parser == null) return null; parser.require(XmlPullParser.START_TAG, null, TAG_FEED); String tag = parser.getName(); if (tag.equals(TAG_FEED)) { // Read attributes String feedTitle = parser.getAttributeValue(null, ATTRIBUTE_FEED_TITLE); String feedVisible = parser.getAttributeValue(null, ATTRIBUTE_VISIBLE); // Read text if (parser.next() == XmlPullParser.TEXT) { String feedText = parser.getText(); if (feedText != null) { feed = new Feed(feedText); if (feedTitle != null) { feed.setTitle(feedTitle); } if (feedVisible != null) { feed.setVisible(!"false".equals(feedVisible)); } } parser.nextTag(); } } parser.require(XmlPullParser.END_TAG, null, TAG_FEED); return feed; }
Example 4
Source File: XmlParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private String parseString(XmlPullParser xpp) throws XmlPullParserException, FHIRFormatError, IOException { StringBuilder res = new StringBuilder(); next(xpp); while (xpp.getEventType() == XmlPullParser.TEXT || xpp.getEventType() == XmlPullParser.IGNORABLE_WHITESPACE || xpp.getEventType() == XmlPullParser.ENTITY_REF) { res.append(xpp.getText()); next(xpp); } if (xpp.getEventType() != XmlPullParser.END_TAG) throw new FHIRFormatError("Bad String Structure - parsed "+res.toString()+" now found "+Integer.toString(xpp.getEventType())); next(xpp); return res.length() == 0 ? null : res.toString(); }
Example 5
Source File: XmlParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
protected int nextNoWhitespace(XmlPullParser xpp) throws XmlPullParserException, IOException { int eventType = xpp.getEventType(); while ((eventType == XmlPullParser.TEXT && xpp.isWhitespace()) || (eventType == XmlPullParser.COMMENT) || (eventType == XmlPullParser.CDSECT) || (eventType == XmlPullParser.IGNORABLE_WHITESPACE) || (eventType == XmlPullParser.PROCESSING_INSTRUCTION) || (eventType == XmlPullParser.DOCDECL)) { if (eventType == XmlPullParser.COMMENT) { comments.add(xpp.getText()); } else if (eventType == XmlPullParser.DOCDECL) { throw new XmlPullParserException("DTD declarations are not allowed"); } eventType = next(xpp); } return eventType; }
Example 6
Source File: News.java From mirror with MIT License | 5 votes |
/** * Reads the contents of a tag by the specified name at the current parser position. */ private String readText(String name) throws IOException, XmlPullParserException { parser.require(XmlPullParser.START_TAG, null, name); String text = ""; if (parser.next() == XmlPullParser.TEXT) { text = parser.getText(); parser.nextTag(); } parser.require(XmlPullParser.END_TAG, null, name); return text; }
Example 7
Source File: SubmitPost.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
@Override protected Void doInBackground(Void... voids) { try { XmlPullParser xmlPullParser = XmlPullParserFactory.newInstance().newPullParser(); xmlPullParser.setInput(new StringReader(response)); boolean isLocationTag = false; int eventType = xmlPullParser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (xmlPullParser.getName().equals("Location")) { isLocationTag = true; } } else if (eventType == XmlPullParser.TEXT) { if (isLocationTag) { imageUrl = xmlPullParser.getText(); successful = true; return null; } } eventType = xmlPullParser.next(); } } catch (XmlPullParserException | IOException e) { e.printStackTrace(); successful = false; } return null; }
Example 8
Source File: GpxParser.java From trekarta with GNU General Public License v3.0 | 5 votes |
private static int readInteger(XmlPullParser parser) throws IOException, XmlPullParserException { String text = ""; if (parser.next() == XmlPullParser.TEXT) { text = parser.getText(); parser.nextTag(); } int result; try { result = Integer.parseInt(text.trim()); } catch (NumberFormatException e) { throw new XmlPullParserException("Expected integer", parser, e); } return result; }
Example 9
Source File: XmlReader.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
public Tag readTag() throws IOException { try { while (this.is != null && parser.next() != XmlPullParser.END_DOCUMENT) { if (parser.getEventType() == XmlPullParser.START_TAG) { Tag tag = Tag.start(parser.getName()); final String xmlns = parser.getNamespace(); for (int i = 0; i < parser.getAttributeCount(); ++i) { final String prefix = parser.getAttributePrefix(i); String name; if (prefix != null && !prefix.isEmpty()) { name = prefix + ":" + parser.getAttributeName(i); } else { name = parser.getAttributeName(i); } tag.setAttribute(name, parser.getAttributeValue(i)); } if (xmlns != null) { tag.setAttribute("xmlns", xmlns); } return tag; } else if (parser.getEventType() == XmlPullParser.END_TAG) { return Tag.end(parser.getName()); } else if (parser.getEventType() == XmlPullParser.TEXT) { return Tag.no(parser.getText()); } } } catch (Throwable throwable) { throw new IOException("xml parser mishandled " + throwable.getClass().getSimpleName() + "(" + throwable.getMessage() + ")", throwable); } return null; }
Example 10
Source File: XmlParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private String parseString(XmlPullParser xpp) throws XmlPullParserException, FHIRFormatError, IOException { StringBuilder res = new StringBuilder(); next(xpp); while (xpp.getEventType() == XmlPullParser.TEXT || xpp.getEventType() == XmlPullParser.IGNORABLE_WHITESPACE || xpp.getEventType() == XmlPullParser.ENTITY_REF) { res.append(xpp.getText()); next(xpp); } if (xpp.getEventType() != XmlPullParser.END_TAG) throw new FHIRFormatError("Bad String Structure - parsed "+res.toString()+" now found "+Integer.toString(xpp.getEventType())); next(xpp); return res.length() == 0 ? null : res.toString(); }
Example 11
Source File: XmlParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
protected int nextNoWhitespace(XmlPullParser xpp) throws XmlPullParserException, IOException { int eventType = xpp.getEventType(); while ((eventType == XmlPullParser.TEXT && xpp.isWhitespace()) || (eventType == XmlPullParser.COMMENT) || (eventType == XmlPullParser.CDSECT) || (eventType == XmlPullParser.IGNORABLE_WHITESPACE) || (eventType == XmlPullParser.PROCESSING_INSTRUCTION) || (eventType == XmlPullParser.DOCDECL)) { if (eventType == XmlPullParser.COMMENT) { comments.add(xpp.getText()); } else if (eventType == XmlPullParser.DOCDECL) { throw new XmlPullParserException("DTD declarations are not allowed"); } eventType = next(xpp); } return eventType; }
Example 12
Source File: ManifestParser.java From Neptune with Apache License 2.0 | 5 votes |
/** * 解析Activity、Service、Recevier等组件节点 */ private ComponentBean parseComponent(XmlResourceParser parser) throws IOException, XmlPullParserException { ComponentBean bean = new ComponentBean(); String name = parser.getAttributeValue(ANDROID_RESOURCES, "name"); bean.className = buildClassName(pkg, name); 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("intent-filter")) { IntentFilter intentFilter = parseIntent(parser); if (intentFilter != null) { bean.intentFilters.add(intentFilter); } } } return bean; }
Example 13
Source File: KeyChainSnapshotDeserializer.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static String readText(XmlPullParser parser) throws IOException, XmlPullParserException { String result = ""; if (parser.next() == XmlPullParser.TEXT) { result = parser.getText(); parser.nextTag(); } return result; }
Example 14
Source File: firmwareEntriesParser.java From SensorTag-CC2650 with Apache License 2.0 | 5 votes |
private int readInt(XmlPullParser parser,String tag) throws XmlPullParserException, IOException { parser.require(XmlPullParser.START_TAG, ns, tag); int temp = 0; if (parser.next() == XmlPullParser.TEXT) { temp = Integer.parseInt(parser.getText()); parser.nextTag(); } parser.require(XmlPullParser.END_TAG, ns, tag); return temp; }
Example 15
Source File: DeviceManager.java From timelapse-sony with GNU General Public License v3.0 | 5 votes |
private String readText(XmlPullParser parser) throws IOException, XmlPullParserException { String result = ""; if (parser.next() == XmlPullParser.TEXT) { result = parser.getText(); parser.nextTag(); } return result; }
Example 16
Source File: RoutesParser.java From VolleyBall with MIT License | 5 votes |
private static Route parse(XmlPullParser aXpp) throws Exception { // Will begin at a START_TAG event type int eventType = aXpp.getEventType(); if (eventType != XmlPullParser.START_TAG) { throw new RuntimeException("Not at correct parse position in routes file"); } Route.Builder builder = new Route.Builder(); String type = aXpp.getAttributeValue(null, "type"); if (type == null) type = "get"; builder.type(type); String path = aXpp.getAttributeValue(null, "path"); if (path == null) { throw new RuntimeException("route tag must contain a path"); } builder.route(path); eventType = aXpp.next(); if (eventType != XmlPullParser.TEXT) { throw new RuntimeException("Not at correct parse position in routes file"); } String value = aXpp.getText(); builder.response(value); // Should verify aParser.next() event is END_TAG eventType = aXpp.next(); if (eventType != XmlPullParser.END_TAG) { throw new RuntimeException("Not at correct parse position in routes file"); } return builder.build(); }
Example 17
Source File: ToolsHelper.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
protected int nextNoWhitespace(XmlPullParser xpp) throws XmlPullParserException, IOException { int eventType = xpp.getEventType(); while (eventType == XmlPullParser.TEXT && xpp.isWhitespace()) eventType = xpp.next(); return eventType; }
Example 18
Source File: PacketParserUtils.java From AndroidPNClient with Apache License 2.0 | 4 votes |
/** * Parses a packet extension sub-packet. * * @param elementName the XML element name of the packet extension. * @param namespace the XML namespace of the packet extension. * @param parser the XML parser, positioned at the starting element of the extension. * @return a PacketExtension. * @throws Exception if a parsing error occurs. */ public static PacketExtension parsePacketExtension(String elementName, String namespace, XmlPullParser parser) throws Exception { // See if a provider is registered to handle the extension. Object provider = ProviderManager.getInstance().getExtensionProvider(elementName, namespace); if (provider != null) { if (provider instanceof PacketExtensionProvider) { return ((PacketExtensionProvider)provider).parseExtension(parser); } else if (provider instanceof Class) { return (PacketExtension)parseWithIntrospection( elementName, (Class)provider, parser); } } // No providers registered, so use a default extension. DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { String name = parser.getName(); // If an empty element, set the value with the empty string. if (parser.isEmptyElementTag()) { extension.setValue(name,""); } // Otherwise, get the the element text. else { eventType = parser.next(); if (eventType == XmlPullParser.TEXT) { String value = parser.getText(); extension.setValue(name, value); } } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(elementName)) { done = true; } } } return extension; }
Example 19
Source File: LayerDrawableInflateImpl.java From timecat with Apache License 2.0 | 4 votes |
@Override public Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException { final int innerDepth = parser.getDepth() + 1; int type; int depth; int layerAttrUseCount = 0; int drawableUseCount = 0; int space = STEP << 1; //L,T,R,B,S,E,id int[][] childLayersAttrs = new int[space][ATTRS.length]; Drawable[] drawables = new Drawable[space]; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG) { continue; } if (depth > innerDepth || !parser.getName().equals("item")) { continue; } if (layerAttrUseCount >= childLayersAttrs.length) { int[][] dstInt = new int[drawables.length + STEP][ATTRS.length]; System.arraycopy(childLayersAttrs, 0, dstInt, 0, childLayersAttrs.length); childLayersAttrs = dstInt; } updateLayerAttrs(context, attrs, childLayersAttrs[layerAttrUseCount]); layerAttrUseCount++; Drawable drawable = DrawableUtils.getAttrDrawable(context, attrs, android.R.attr.drawable); // If the layer doesn't have a drawable or unresolved theme // attribute for a drawable, attempt to parse one from the child // element. if (drawable == null) { while ((type = parser.next()) == XmlPullParser.TEXT) { } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable"); } drawable = DrawableUtils.createFromXmlInner(context, parser, attrs); } else { final ColorStateList cls = DrawableUtils.getTintColorList(context, attrs, R.attr.drawableTint); if (cls != null) { drawable = ThemeUtils.tintDrawable(drawable, cls, DrawableUtils.getTintMode(context, attrs, R.attr.drawableTintMode)); } } if (drawable != null) { if (drawableUseCount >= drawables.length) { Drawable[] dst = new Drawable[drawables.length + STEP]; System.arraycopy(drawables, 0, dst, 0, drawables.length); drawables = dst; } drawables[drawableUseCount] = drawable; drawableUseCount++; } } if (drawables[0] == null || drawableUseCount != layerAttrUseCount) { return null; } else { LayerDrawable layerDrawable = new LayerDrawable(drawables); for (int i = 0; i < drawables.length; i++) { int[] childLayersAttr = childLayersAttrs[i]; if (childLayersAttr[0] != 0 || childLayersAttr[1] != 0 || childLayersAttr[2] != 0 || childLayersAttr[3] != 0) { layerDrawable.setLayerInset(i, childLayersAttr[0], childLayersAttr[1], childLayersAttr[2], childLayersAttr[3]); } if (childLayersAttr[4] != 0) { layerDrawable.setId(i, childLayersAttr[4]); } } return layerDrawable; } }
Example 20
Source File: ToolsHelper.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
protected int nextNoWhitespace(XmlPullParser xpp) throws XmlPullParserException, IOException { int eventType = xpp.getEventType(); while (eventType == XmlPullParser.TEXT && xpp.isWhitespace()) eventType = xpp.next(); return eventType; }