Java Code Examples for javax.xml.stream.XMLStreamReader#CHARACTERS
The following examples show how to use
javax.xml.stream.XMLStreamReader#CHARACTERS .
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: XMLStreamReaderTest.java From FHIR with Apache License 2.0 | 6 votes |
private static void debug(XMLStreamReader reader) throws XMLStreamException { int eventType = reader.getEventType(); switch (eventType) { case XMLStreamReader.START_DOCUMENT: System.out.println("START_DOCUMENT"); break; case XMLStreamReader.START_ELEMENT: System.out.println("START_ELEMENT: " + reader.getLocalName()); break; case XMLStreamReader.SPACE: System.out.println("SPACE"); break; case XMLStreamReader.CHARACTERS: System.out.println("CHARACTERS"); break; case XMLStreamReader.END_ELEMENT: System.out.println("END_ELEMENT: " + reader.getLocalName()); break; case XMLStreamReader.END_DOCUMENT: System.out.println("END_DOCUMENT"); break; default: System.out.println("OTHER: " + eventType); break; } }
Example 2
Source File: StaxUtils.java From grobid-ner with Apache License 2.0 | 6 votes |
public static Map<String, String> parse(XMLStreamReader streamReader, EndCondition endCondition, String... tags) throws XMLStreamException { Map<String, String> mapping = new HashMap<String, String>(); while (streamReader.hasNext() && !endCondition.mustExit(streamReader)) { streamReader.next(); if (XMLStreamReader.START_ELEMENT == streamReader.getEventType()) { String localPart = streamReader.getName().getLocalPart(); for (String tag : tags) { if (tag.equals(localPart)) { streamReader.next(); if (XMLStreamReader.CHARACTERS == streamReader.getEventType()) { mapping.put(tag, streamReader.getText()); } } } } } return mapping; }
Example 3
Source File: XmlPullProcessor.java From morf with Apache License 2.0 | 6 votes |
/** * Reads the next tag from the pull parser and throws an exception if its name does not * match <var>expectedTagName</var>. * * @param xmlPullParser The pull parser to read from * @param expectedTagName The tag name expected */ public static void readTag(XMLStreamReader xmlStreamReader, String expectedTagName) { // Look for any start tag event int event; try { do { event = xmlStreamReader.next(); } while (event == XMLStreamReader.CHARACTERS || event == XMLStreamReader.END_ELEMENT || event == XMLStreamReader.COMMENT); } catch (Exception e) { throw new RuntimeException("Error reading data from the XML pull parser", e); } if (event == XMLStreamReader.START_ELEMENT) { if (!expectedTagName.equals(xmlStreamReader.getLocalName())) { throw new IllegalArgumentException("Expected tag [" + expectedTagName + "] but got [" + xmlStreamReader.getLocalName() + "]"); } } else if (event == XMLStreamReader.END_DOCUMENT) { throw new IllegalStateException("Unexpected end of document while looking for tag [" + expectedTagName + "]"); } else { throw new IllegalStateException("Expecting a tag but found [" + event + "]"); } }
Example 4
Source File: XMLSupport.java From FHIR with Apache License 2.0 | 5 votes |
public static String parseDiv(XMLStreamReader reader) throws XMLStreamException { int depth = 0; StringWriter sw = new StringWriter(); XMLStreamWriter writer = createStreamWriterDelegate(sw); depth++; writeStartElement(reader, writer); while (reader.hasNext()) { int eventType = reader.next(); switch (eventType) { case XMLStreamReader.START_ELEMENT: requireNamespace(reader, XHTML_NS_URI); depth++; writeStartElement(reader, writer); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: writer.writeCharacters(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); break; case XMLStreamReader.END_ELEMENT: writer.writeEndElement(); depth--; if ("div".equals(reader.getLocalName()) && depth == 0) { writer.flush(); writer.close(); return sw.toString(); } break; } } throw new XMLStreamException("Unexpected end of stream"); }
Example 5
Source File: XmlDecoder.java From opc-ua-stack with Apache License 2.0 | 5 votes |
private String readCharacterContent() throws UaSerializationException { try { while (streamReader.hasNext()) { streamReader.next(); if (streamReader.getEventType() == XMLStreamReader.CHARACTERS) { return streamReader.getText(); } } throw new UaSerializationException(StatusCodes.Bad_DecodingError, "no character content found"); } catch (XMLStreamException e) { throw new UaSerializationException(StatusCodes.Bad_DecodingError, e); } }
Example 6
Source File: Cfg.java From aion_api with MIT License | 5 votes |
public static String readValue(final XMLStreamReader sr) throws XMLStreamException { StringBuilder str = new StringBuilder(); readLoop: while (sr.hasNext()) { int eventType = sr.next(); switch (eventType) { case XMLStreamReader.CHARACTERS: str.append(sr.getText()); break; case XMLStreamReader.END_ELEMENT: break readLoop; } } return str.toString(); }
Example 7
Source File: StaxConfigTokenizer.java From cache2k with Apache License 2.0 | 5 votes |
@Override public Item next() throws Exception { while (input.hasNext()) { int type = input.next(); switch (type) { case XMLStreamReader.START_ELEMENT : if (startName != null) { hierarchy.push(startName); startName = input.getLocalName(); return returnNest(hierarchy.element()); } startName = input.getLocalName(); break; case XMLStreamReader.CHARACTERS : value = input.getText(); break; case XMLStreamReader.END_ELEMENT : String name = input.getLocalName(); if (startName != null && startName.equals(name)) { startName = null; return returnProperty(name, value); } if (name.equals(hierarchy.element())) { hierarchy.pop(); return returnUnnest(); } break; } } return null; }
Example 8
Source File: BooksReader.java From softwarecave with GNU General Public License v3.0 | 5 votes |
private String readCharacters(XMLStreamReader reader) throws XMLStreamException { StringBuilder result = new StringBuilder(); while (reader.hasNext()) { int eventType = reader.next(); switch (eventType) { case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: result.append(reader.getText()); break; case XMLStreamReader.END_ELEMENT: return result.toString(); } } throw new XMLStreamException("Premature end of file"); }
Example 9
Source File: StreamReaderBufferCreator.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { CharSequence c = reader.getPCDATA(); if (c instanceof Base64Data) { storeStructure(T_TEXT_AS_OBJECT); //Instead of clone the Base64Data, the original Base64Data instance is used here to preserve the DataHandler storeContentObject(c); } else { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); } break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 10
Source File: StreamReaderBufferCreator.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenNoEx(XMLStreamReader reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 11
Source File: StreamReaderBufferCreator.java From hottub with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenNoEx(XMLStreamReader reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 12
Source File: StreamReaderBufferCreator.java From hottub with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { CharSequence c = reader.getPCDATA(); if (c instanceof Base64Data) { storeStructure(T_TEXT_AS_OBJECT); //Instead of clone the Base64Data, the original Base64Data instance is used here to preserve the DataHandler storeContentObject(c); } else { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); } break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 13
Source File: VespaXMLFieldReader.java From vespa with Apache License 2.0 | 4 votes |
public void read(FieldBase field, Struct value) { try { boolean base64 = isBase64EncodedElement(reader); boolean foundField = false; StringBuilder positionBuilder = null; while (reader.hasNext()) { int type = reader.next(); if (type == XMLStreamReader.START_ELEMENT) { Field structField = value.getField(reader.getName().toString()); if (structField == null) { throw newDeserializeException(field, "Field " + reader.getName() + " not found."); } FieldValue fieldValue = structField.getDataType().createFieldValue(); fieldValue.deserialize(structField, this); value.setFieldValue(structField, fieldValue); skipToEnd(structField.getName()); foundField = true; } else if (type == XMLStreamReader.CHARACTERS) { if (foundField) { continue; } // The text of an XML element may be output using 1-n CHARACTERS // events, so we have to buffer up until the end of the element to // ensure we get everything. String chars = reader.getText(); if (positionBuilder == null) { positionBuilder = new StringBuilder(chars); } else { positionBuilder.append(chars); } } else if (type == XMLStreamReader.END_ELEMENT) { if (positionBuilder != null) { assignPositionFieldFromStringIfNonEmpty(value, positionBuilder.toString(), base64); } break; } } } catch (XMLStreamException e) { throw newException(field, e); } }
Example 14
Source File: StreamReaderBufferCreator.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { CharSequence c = reader.getPCDATA(); if (c instanceof Base64Data) { storeStructure(T_TEXT_AS_OBJECT); //Instead of clone the Base64Data, the original Base64Data instance is used here to preserve the DataHandler storeContentObject(c); } else { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); } break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 15
Source File: StreamReaderBufferCreator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenNoEx(XMLStreamReader reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 16
Source File: StreamReaderBufferCreator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { CharSequence c = reader.getPCDATA(); if (c instanceof Base64Data) { storeStructure(T_TEXT_AS_OBJECT); //Instead of clone the Base64Data, the original Base64Data instance is used here to preserve the DataHandler storeContentObject(c); } else { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); } break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 17
Source File: StreamReaderBufferCreator.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenNoEx(XMLStreamReader reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 18
Source File: StreamReaderBufferCreator.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { CharSequence c = reader.getPCDATA(); if (c instanceof Base64Data) { storeStructure(T_TEXT_AS_OBJECT); //Instead of clone the Base64Data, the original Base64Data instance is used here to preserve the DataHandler storeContentObject(c); } else { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); } break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 19
Source File: StreamReaderBufferCreator.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenNoEx(XMLStreamReader reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }
Example 20
Source File: StreamReaderBufferCreator.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException { int depth = 1; if (_storeInScopeNamespacesOnElementFragment) { storeElementWithInScopeNamespaces(reader); } else { storeElement(reader); } while(depth > 0) { _eventType = reader.next(); switch (_eventType) { case XMLStreamReader.START_ELEMENT: depth++; storeElement(reader); break; case XMLStreamReader.END_ELEMENT: depth--; storeStructure(T_END); break; case XMLStreamReader.NAMESPACE: storeNamespaceAttributes(reader); break; case XMLStreamReader.ATTRIBUTE: storeAttributes(reader); break; case XMLStreamReader.SPACE: case XMLStreamReader.CHARACTERS: case XMLStreamReader.CDATA: { CharSequence c = reader.getPCDATA(); if (c instanceof Base64Data) { storeStructure(T_TEXT_AS_OBJECT); //Instead of clone the Base64Data, the original Base64Data instance is used here to preserve the DataHandler storeContentObject(c); } else { storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength()); } break; } case XMLStreamReader.COMMENT: storeComment(reader); break; case XMLStreamReader.PROCESSING_INSTRUCTION: storeProcessingInstruction(reader); break; } } /* * Move to next item after the end of the element * that has been stored */ _eventType = reader.next(); }