Subject: [xsl] Spliting an xml document into another document From: Sabrina Fords <Sabrina.Fords@xxxxxxxxxx> Date: Wed, 9 Jan 2002 15:28:43 -0000 |
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@xxxxxxxxxx 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] use cases for d-o-e, Joerg Pietschmann | Thread | Re: [xsl] Spliting an xml document , Mulberry Technologie |
RE: [xsl] use cases for d-o-e, Michael Kay | Date | Re: [xsl] Content constructors and , Jeni Tennison |
Month |