XmlShredder extends AbstractShredder implements Callable<Long> { public static void main(final String... args) throws SirixException, IOException, XMLStreamException { if (args.length != 2 && args.length != 3) { throw new IllegalArgumentException("Usage: XMLShredder XMLFile Database [true/false] (shredder comment|PI)"); } LOGWRAPPER.info("Shredding '" + args[0] + "' to '" + args[1] + "' ... "); final long time = System.nanoTime(); final Path target = Paths.get(args[1]); final DatabaseConfiguration config = new DatabaseConfiguration(target); Databases.removeDatabase(target); Databases.createXmlDatabase(config); try (final var db = Databases.openXmlDatabase(target)) { db.createResource(new ResourceConfiguration.Builder("shredded").build()); try (final XmlResourceManager resMgr = db.openResourceManager("shredded"); final XmlNodeTrx wtx = resMgr.beginNodeTrx(); final FileInputStream fis = new FileInputStream(Paths.get(args[0]).toFile())) { final XMLEventReader reader = createFileReader(fis); final boolean includeCoPI = args.length == 3 ? Boolean.parseBoolean(args[2]) : false; final XmlShredder shredder = new XmlShredder.Builder(wtx, reader, InsertPosition.AS_FIRST_CHILD).commitAfterwards() .includeComments(includeCoPI) .includePIs(includeCoPI) .build(); shredder.call(); } } LOGWRAPPER.info(" done [" + (System.nanoTime() - time) / 1000000 + " ms]."); } private  XmlShredder(final Builder builder); @Override Long call(); static void main(final String... args); static XMLEventReader createFileReader(final FileInputStream fis); static XMLEventReader createStringReader(final String xmlString); static XMLEventReader createQueueReader(final Queue<XMLEvent> events);  }
@Test public void testSTAXShredder() throws Exception { XmlShredder.main(XML.toAbsolutePath().toString(), PATHS.PATH2.getFile().toAbsolutePath().toString()); final XmlNodeReadOnlyTrx expectedTrx = holder.getXdmNodeWriteTrx(); final var database2 = XmlTestHelper.getDatabase(PATHS.PATH2.getFile()); database2.createResource(new ResourceConfiguration.Builder(XmlTestHelper.RESOURCE).build()); final XmlResourceManager manager = database2.openResourceManager(XmlTestHelper.RESOURCE); final XmlNodeReadOnlyTrx rtx = manager.beginNodeReadOnlyTrx(); rtx.moveToDocumentRoot(); final Iterator<Long> expectedDescendants = new DescendantAxis(expectedTrx); final Iterator<Long> descendants = new DescendantAxis(rtx); while (expectedDescendants.hasNext() && descendants.hasNext()) { assertEquals(expectedTrx.getNodeKey(), rtx.getNodeKey()); assertEquals(expectedTrx.getParentKey(), rtx.getParentKey()); assertEquals(expectedTrx.getFirstChildKey(), rtx.getFirstChildKey()); assertEquals(expectedTrx.getLeftSiblingKey(), rtx.getLeftSiblingKey()); assertEquals(expectedTrx.getRightSiblingKey(), rtx.getRightSiblingKey()); assertEquals(expectedTrx.getChildCount(), rtx.getChildCount()); if (expectedTrx.getKind() == NodeKind.ELEMENT || rtx.getKind() == NodeKind.ELEMENT) { assertEquals(expectedTrx.getAttributeCount(), rtx.getAttributeCount()); assertEquals(expectedTrx.getNamespaceCount(), rtx.getNamespaceCount()); } assertEquals(expectedTrx.getKind(), rtx.getKind()); assertEquals(expectedTrx.getName(), rtx.getName()); assertEquals(expectedTrx.getValue(), expectedTrx.getValue()); } rtx.close(); manager.close(); database2.close(); expectedTrx.close(); }