VoiceXmlDocument extends XmlDocument implements Serializable { public Vxml getVxml() { NodeList vxml = getElementsByTagName(Vxml.TAG_NAME); if (vxml.getLength() == 0) { vxml = getElementsByTagNameNS("*", Vxml.TAG_NAME); if (vxml.getLength() == 0) { return null; } } return (Vxml) vxml.item(0); } VoiceXmlDocument();  VoiceXmlDocument(final InputSource source);  VoiceXmlDocument(final Document doc); static void setDocumentTypeFactory(
            final DocumentTypeFactory factory); @Override DocumentType getDoctype(); @Override XmlNodeFactory<?> getXmlNodefactory(); Vxml getVxml();  }
@Test public void testSerialize() throws Exception { System.setProperty("jvoicexml.xml.encoding", "UTF-8"); final VoiceXmlDocument doc = new VoiceXmlDocument(); final Vxml vxml = doc.getVxml(); final Form form = vxml.appendChild(Form.class); final Block block = form.appendChild(Block.class); block.setName("testäöü"); final File file = File.createTempFile("jvxmltest", null); file.deleteOnExit(); final FileOutputStream fout = new FileOutputStream(file); final ObjectOutputStream oo = new ObjectOutputStream(fout); oo.writeObject(doc); oo.close(); fout.close(); final String expected = doc.toString(); System.setProperty("jvoicexml.xml.encoding", "UTF-16"); final FileInputStream fin = new FileInputStream(file); final ObjectInputStream oi = new ObjectInputStream(fin); final Object o = oi.readObject(); oi.close(); fin.close(); Assert.assertEquals(expected, o.toString()); }
@Test public void testSerializeLargeDocument() throws Exception { System.setProperty("jvoicexml.xml.encoding", "ISO-8859-1"); final VoiceXmlDocument doc = new VoiceXmlDocument(); final Vxml vxml = doc.getVxml(); for (int i = 0; i < 10000; i++) { final Form form = vxml.appendChild(Form.class); form.setId("form " + i); final Block block = form.appendChild(Block.class); block.setName("block " + i); } final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeObject(doc); final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final ObjectInputStream oin = new ObjectInputStream(in); final Object o = oin.readObject(); Assert.assertEquals(doc.toString(), o.toString()); }