You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by ba...@standardandpoors.com on 2001/03/30 19:12:33 UTC
create/serialize sub-documents
Help.
I have a file like:
<toptag>
<article>
............lots of stuff
</article>
<article>
............more stuff
</article>
</toptag>
I want TWO files like:
<article>
.........stuff
</article>
Using something like Sebastien Ponce's code:
parser.parse(uri);
Document doc = parser.getDocument();
NodeList nodeList = doc.getElementsByTagName("article");
String fileNumber;
for (int i=0;i<nodeList.getLength();i++){
Node node = nodeList.item(i);
Document newDoc = new DocumentImpl();
newDoc.importNode(node,true);
OutputFormat of = new OutputFormat(newDoc);
of.setPreserveSpace(false);
of.setIndent(5);
of.setLineWidth(80);
fileNumber = Integer.toString(i);
BufferedOutputStream oStream = new BufferedOutputStream(new
FileOutputStream("temp"+fileNumber+".xml"));
XMLSerializer ser = new XMLSerializer(oStream,of);
ser.serialize(newDoc);
oStream.close();
}
I get two EMPTY files. Please tell me what I am missing. Thanks for your
consideration.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org