I've done the exact same thing using the SAXParser. It's a little more work to keep track of the stack of elements, but it works well. If you want a code sample, let me know and I can send you one.
Matt Olsen
Programmer
Ovid Technologies
(801)304-3372
[EMAIL PROTECTED]
dpoors.com To: [EMAIL PROTECTED]
cc:
03/30/01 10:21 AM Fax to:
Please respond to Subject: RE:
create/serialize sub-documents
xerces-j-user
As soon as put in newDoc.appendChild(node) after importNode, I get runtime
error:
DOM Parsing error DOM005 Wrong document
Lei Chen <[EMAIL PROTECTED]> on 03/30/2001 12:16:44 PM
Please respond to [EMAIL PROTECTED]
To: "'[EMAIL PROTECTED]'"
<[EMAIL PROTECTED]>
cc: (bcc: Barry Nobel/IN/FIS)
Subject: RE: create/serialize sub-documents
I think you forgot to call newDoc.appendChild(node) after importNode
-Lei
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Friday, March 30, 2001 12:13 PM
To: [EMAIL PROTECTED]
Subject: 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
(See attached file: att1.htm)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Title: RE: create/serialize sub-documents
I think you forgot to call newDoc.appendChild(node) after importNode
-Lei
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: Friday, March 30, 2001 12:13 PM
To: [EMAIL PROTECTED]
Subject: 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
