Java Code Examples for javax.xml.stream.XMLStreamReader#COMMENT

The following examples show how to use javax.xml.stream.XMLStreamReader#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: StreamReaderBufferCreator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void storeDocumentAndChildren(XMLStreamReader reader) throws XMLStreamException {
    storeStructure(T_DOCUMENT);

    _eventType = reader.next();
    while (_eventType != XMLStreamReader.END_DOCUMENT) {
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                storeElementAndChildren(reader);
                continue;
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
        _eventType = reader.next();
    }

    storeStructure(T_END);
}
 
Example 2
Source File: StreamReaderBufferCreator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void storeDocumentAndChildren(XMLStreamReader reader) throws XMLStreamException {
    storeStructure(T_DOCUMENT);

    _eventType = reader.next();
    while (_eventType != XMLStreamReader.END_DOCUMENT) {
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                storeElementAndChildren(reader);
                continue;
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
        _eventType = reader.next();
    }

    storeStructure(T_END);
}
 
Example 3
Source File: StreamReaderBufferCreator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void storeDocumentAndChildren(XMLStreamReader reader) throws XMLStreamException {
    storeStructure(T_DOCUMENT);

    _eventType = reader.next();
    while (_eventType != XMLStreamReader.END_DOCUMENT) {
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                storeElementAndChildren(reader);
                continue;
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
        _eventType = reader.next();
    }

    storeStructure(T_END);
}
 
Example 4
Source File: StreamReaderBufferCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void storeDocumentAndChildren(XMLStreamReader reader) throws XMLStreamException {
    storeStructure(T_DOCUMENT);

    _eventType = reader.next();
    while (_eventType != XMLStreamReader.END_DOCUMENT) {
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                storeElementAndChildren(reader);
                continue;
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
        _eventType = reader.next();
    }

    storeStructure(T_END);
}
 
Example 5
Source File: XmlPullProcessor.java    From morf with Apache License 2.0 6 votes vote down vote up
/**
 * 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 6
Source File: StreamReaderBufferCreator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void storeDocumentAndChildren(XMLStreamReader reader) throws XMLStreamException {
    storeStructure(T_DOCUMENT);

    _eventType = reader.next();
    while (_eventType != XMLStreamReader.END_DOCUMENT) {
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                storeElementAndChildren(reader);
                continue;
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
        _eventType = reader.next();
    }

    storeStructure(T_END);
}
 
Example 7
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testLongCommentNextTag() throws Exception {
    try {
        Reader reader = createLongReader("<!--", "-->", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.COMMENT) {
        }
        xmlreader.nextTag();
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example 8
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testLongComment() throws Exception {
    try {
        Reader reader = createLongReader("<!--", "-->", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.COMMENT) {
        }
        // important, due to lazy handling only triggers problem here:
        String str = xmlreader.getText();
        fail("Should have failed; instead got: "+str);
    } catch (Exception ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example 9
Source File: StreamReaderBufferCreator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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 hottub with GNU General Public License v2.0 4 votes vote down vote up
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 11
Source File: StreamReaderBufferCreator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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 openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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 13
Source File: StreamReaderBufferCreator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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 14
Source File: StreamReaderBufferCreator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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 15
Source File: StreamReaderBufferCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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 with GNU General Public License v2.0 4 votes vote down vote up
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-8-source with GNU General Public License v2.0 4 votes vote down vote up
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 vote down vote up
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 vote down vote up
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 vote down vote up
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();
}