Java Code Examples for org.xmlpull.v1.XmlPullParser#COMMENT
The following examples show how to use
org.xmlpull.v1.XmlPullParser#COMMENT .
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: EXIPullParser.java From exificient with MIT License | 6 votes |
public String getText() { try { switch (getEventType()) { case XmlPullParser.TEXT: return characters.toString(); case XmlPullParser.COMMENT: return new String(comment); case XmlPullParser.ENTITY_REF: return new String(this.entityReference); case XmlPullParser.DOCDECL: return getDocTypeString(); default: throw new RuntimeException("Unexpected event, id=" + getEventType()); } } catch (XmlPullParserException e) { throw new RuntimeException("Unexpected text, error=" + e.getMessage()); } }
Example 2
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 3
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 4
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()); } eventType = next(xpp); } return eventType; }
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: 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 7
Source File: XhtmlParser.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private XhtmlNode parseNode(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError { XhtmlNode res = new XhtmlNode(NodeType.Element); res.setName(xpp.getName()); for (int i = 0; i < xpp.getAttributeCount(); i++) { String an = "xml".equals(xpp.getAttributePrefix(i)) ? "xml:"+xpp.getAttributeName(i) : xpp.getAttributeName(i); String av = xpp.getAttributeValue(i); if (attributeIsOk(xpp.getName(), an, av)) { res.getAttributes().put(an, av); } } int eventType = xpp.next(); while (eventType != XmlPullParser.END_TAG) { if (eventType == XmlPullParser.TEXT) { res.addText(xpp.getText()); xpp.next(); } else if (eventType == XmlPullParser.COMMENT) { res.addComment(xpp.getText()); xpp.next(); } else if (eventType == XmlPullParser.START_TAG) { if (elementIsOk(xpp.getName())) res.getChildNodes().add(parseNode(xpp)); } else throw new FHIRFormatError("Unhandled XHTML feature: "+Integer.toString(eventType)+descLoc()); eventType = xpp.getEventType(); } xpp.next(); return res; }
Example 8
Source File: EXIPullParser.java From exificient with MIT License | 5 votes |
public boolean isWhitespace() throws XmlPullParserException { switch (getEventType()) { case XmlPullParser.TEXT: return this.characters.toString().trim().length() == 0; case XmlPullParser.CDSECT: return false; case XmlPullParser.COMMENT: return false; default: return false; } }
Example 9
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 10
Source File: DashManifestParser.java From TelePlus-Android with GNU General Public License v2.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, null); // 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 11
Source File: DashManifestParser.java From TelePlus-Android with GNU General Public License v2.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, null); // 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 12
Source File: EXIPullParser.java From exificient with MIT License | 4 votes |
protected static int getEventType(EventType eventType) { assert (eventType != null); switch (eventType) { case START_DOCUMENT: return XmlPullParser.START_DOCUMENT; case ATTRIBUTE_XSI_TYPE: case ATTRIBUTE_XSI_NIL: case ATTRIBUTE: case ATTRIBUTE_NS: case ATTRIBUTE_GENERIC: case ATTRIBUTE_INVALID_VALUE: case ATTRIBUTE_ANY_INVALID_VALUE: case ATTRIBUTE_GENERIC_UNDECLARED: return -2; case START_ELEMENT: case START_ELEMENT_NS: case START_ELEMENT_GENERIC: case START_ELEMENT_GENERIC_UNDECLARED: return XmlPullParser.START_TAG; case END_ELEMENT: case END_ELEMENT_UNDECLARED: return XmlPullParser.END_TAG; case CHARACTERS: case CHARACTERS_GENERIC: case CHARACTERS_GENERIC_UNDECLARED: return XmlPullParser.TEXT; case END_DOCUMENT: return XmlPullParser.END_DOCUMENT; case DOC_TYPE: return XmlPullParser.DOCDECL; case NAMESPACE_DECLARATION: return -3; case SELF_CONTAINED: // TODO SC return -1; case ENTITY_REFERENCE: return XmlPullParser.ENTITY_REF; case COMMENT: return XmlPullParser.COMMENT; case PROCESSING_INSTRUCTION: return XmlPullParser.PROCESSING_INSTRUCTION; default: throw new RuntimeException("Unexpected EXI Event '" + eventType + "' "); } }
Example 13
Source File: DashManifestParser.java From Telegram-FOSS with GNU General Public License v2.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 14
Source File: DashManifestParser.java From Telegram with GNU General Public License v2.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(); }