XMLMultipleEventWriter extends EventWriterDelegate { @Override public void add(XMLEventReader reader) throws XMLStreamException { while (reader.hasNext()) { add(reader.nextEvent()); } } XMLMultipleEventWriter(XMLEventWriter parent, boolean matchRoot, String... multiplePaths); @Override void setParent(XMLEventWriter parent); void addMultiplePath(String path); @Override void add(XMLEventReader reader); @Override void add(XMLEvent event);  }
@Test public void test1() throws XMLStreamException { StringReader input = new StringReader("<alice><bob>charlie</bob></alice>"); StringWriter output = new StringWriter(); XMLEventReader reader = XMLInputFactory.newFactory().createXMLEventReader(input); XMLOutputFactory factory = new JsonXMLOutputFactory(); factory.setProperty(JsonXMLOutputFactory.PROP_MULTIPLE_PI, true); XMLEventWriter writer = factory.createXMLEventWriter(output); writer = new XMLMultipleEventWriter(writer, true, "/alice/bob"); writer.add(reader); writer.close(); Assert.assertEquals("{\"alice\":{\"bob\":[\"charlie\"]}}", output.toString()); }
@Test public void test2() throws XMLStreamException { StringReader input = new StringReader("<alice><bob>charlie</bob></alice>"); StringWriter output = new StringWriter(); XMLEventReader reader = XMLInputFactory.newFactory().createXMLEventReader(input); XMLOutputFactory factory = new JsonXMLOutputFactory(); factory.setProperty(JsonXMLOutputFactory.PROP_MULTIPLE_PI, true); XMLEventWriter writer = factory.createXMLEventWriter(output); writer = new XMLMultipleEventWriter(writer, false, "/bob"); writer.add(reader); writer.close(); Assert.assertEquals("{\"alice\":{\"bob\":[\"charlie\"]}}", output.toString()); }