private final static XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
private XMLEventReader eventReader;
- public CompositeNodeWrapper read(InputStream entityStream) throws XMLStreamException, UnsupportedFormatException,
- IOException {
- // Get an XML stream which can be marked, and reset, so we can check and
- // see if there is
- // any content being provided.
+ public Node<?> read(InputStream entityStream) throws XMLStreamException,
+ UnsupportedFormatException,
+ IOException {
+ //Get an XML stream which can be marked, and reset, so we can check and see if there is
+ //any content being provided.
entityStream = getMarkableStream(entityStream);
if (isInputStreamEmpty(entityStream)) {
}
}
- if (eventReader.hasNext() && !isCompositeNodeEvent(eventReader.peek())) {
- throw new UnsupportedFormatException("Root element of XML has to be composite element.");
- }
-
final Stack<NodeWrapper<?>> processingQueue = new Stack<>();
- CompositeNodeWrapper root = null;
+ NodeWrapper<?> root = null;
NodeWrapper<?> element = null;
while (eventReader.hasNext()) {
final XMLEvent event = eventReader.nextEvent();
}
NodeWrapper<?> newNode = null;
if (isCompositeNodeEvent(event)) {
+ newNode = resolveCompositeNodeFromStartElement(startElement);
if (root == null) {
- root = resolveCompositeNodeFromStartElement(startElement);
- newNode = root;
- } else {
- newNode = resolveCompositeNodeFromStartElement(startElement);
+ root = newNode;
}
} else if (isSimpleNodeEvent(event)) {
+ newNode = resolveSimpleNodeFromStartElement(startElement);
if (root == null) {
- throw new UnsupportedFormatException("Root element of XML has to be composite element.");
+ root = newNode;
}
- newNode = resolveSimpleNodeFromStartElement(startElement);
}
if (newNode != null) {
throw new UnsupportedFormatException("XML should contain only one root element");
}
- return root;
+ return (Node<?>) root;
}
/**
- * If the input stream is not markable, then it wraps the input stream with
- * a buffered stream, which is mark able. That way we can check if the
- * stream is empty safely.
+ * If the input stream is not markable, then it wraps the input stream with a buffered stream, which is mark able.
+ * That way we can check if the stream is empty safely.
*
* @param entityStream
* @return