@Test public void test2() throws XMLStreamException { DocumentBuilder documentBuilder; try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new XMLStreamException(e); } StringReader json = new StringReader("{\"alice\":{\"@edgar\":\"david\",\"bob\":\"charlie\"}}"); XMLEventReader reader = new JsonXMLInputFactory().createXMLEventReader(json); Document document = documentBuilder.newDocument(); Node node = document.createElement("foo"); document.appendChild(node); DOMEventConsumer.consume(reader, node); Node alice = node.getChildNodes().item(0); Assert.assertEquals("alice", alice.getLocalName()); Assert.assertEquals("david", alice.getAttributes().getNamedItem("edgar").getNodeValue()); Node bob = alice.getChildNodes().item(0); Assert.assertEquals("bob", bob.getLocalName()); Assert.assertEquals("charlie", bob.getTextContent()); }
public static Document consume(XMLEventReader reader) throws XMLStreamException { DocumentBuilder documentBuilder; try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new XMLStreamException(e); } return consume(reader, documentBuilder); }
DOMEventConsumer implements XMLEventConsumer { public static Document consume(XMLEventReader reader) throws XMLStreamException { DocumentBuilder documentBuilder; try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new XMLStreamException(e); } return consume(reader, documentBuilder); } }
DOMEventConsumer implements XMLEventConsumer { public static Document consume(XMLEventReader reader) throws XMLStreamException { DocumentBuilder documentBuilder; try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new XMLStreamException(e); } return consume(reader, documentBuilder); } DOMEventConsumer(Node node);  DOMEventConsumer(Node node, boolean namespaceAware); }
DOMEventConsumer implements XMLEventConsumer { public static Document consume(XMLEventReader reader) throws XMLStreamException { DocumentBuilder documentBuilder; try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new XMLStreamException(e); } return consume(reader, documentBuilder); } DOMEventConsumer(Node node);  DOMEventConsumer(Node node, boolean namespaceAware); @Override void add(XMLEvent event); void add(XMLEventReader reader); static Document consume(XMLEventReader reader); static Document consume(XMLEventReader reader, DocumentBuilder documentBuilder); static void consume(XMLEventReader reader, Node node); }
DOMEventConsumer implements XMLEventConsumer { public static Document consume(XMLEventReader reader) throws XMLStreamException { DocumentBuilder documentBuilder; try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new XMLStreamException(e); } return consume(reader, documentBuilder); } DOMEventConsumer(Node node);  DOMEventConsumer(Node node, boolean namespaceAware); @Override void add(XMLEvent event); void add(XMLEventReader reader); static Document consume(XMLEventReader reader); static Document consume(XMLEventReader reader, DocumentBuilder documentBuilder); static void consume(XMLEventReader reader, Node node);  }