This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Spliting an xml document into another document
- From: Sabrina Fords <Sabrina dot Fords at Yakara dot com>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 9 Jan 2002 15:28:43 -0000
- Subject: [xsl] Spliting an xml document into another document
- Reply-to: xsl-list at lists dot mulberrytech dot com
Apologies if this is the wrong place to post my query.
I have xml document as follows :
<CDRList>
<cdr>
<dpc>344</dpc>
<opc>56</opc>
</cdr>
<cdr>
<dpc>144</dpc>
<opc>16</opc>
</cdr>
<cdr>
<dpc>244</dpc>
<opc>26</opc>
</cdr>
</CDRList>
I parse the document using the following code
// Parse in XML file, and construct a document
DOMParser domParser = new DOMParser();
domParser.parse("sample.xml");
// construct a document
Document document = domParser.getDocument();
//get the root node in the DOM tree
Element topLevel = document.getDocumentElement();
// get children nodes - these will represent cdr
NodeList childNodes = topLevel.getChildNodes();
I now want to create a new document containing the first two children
nodes of the sample.xml document.
I do it using the following code
Document doc = (Document)
Class.forName("org.apache.xerces.dom.DocumentImpl").newInstance();
//create a temp root node
Element root = doc.createElement("temp");
int iNodeCounter =0;
while(childNodes != null & iNodeCounter < 2)
{
child = childNodes.item(iNodeCounter);
if(child.getNodeType() == Node.ELEMENT_NODE)
{
root.appendChild(child);
}
++iNodeCounter
}
doc.appendChild(root);
I now pass this doc to be transformed using my TraX
TransformerFactory m_Factory = TransformerFactory.newInstance();
Templates m_Templates = m_Factory.newTemplates(new
StreamSource(m_strStyleSheet));
DOMSource domSource = new DOMSource(node);
stringWriter = new StringWriter();
Transformer m_Transformer = m_Templates.newTransformer();
m_Transformer.transform(domSource, new StreamResult(stringWriter));
this results in the following exception
org.w3c.dom.DOMException: D0M005 Wrong document
Does anyone know what I'm doing wrong?
thanks in advance
Sabrina
e-mail and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you are not an intended recipient, please notify info@yakara.com
immediately. Please note that some of our communications may contain
confidential information which it could be a criminal offence for you to
disclose or use without authority. This email is not intended nor should it
be taken to create any legal relations contractual or otherwise.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list