[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Spliting an xml document into another document

Subject: Spliting an xml document into another document
From: Sabrina Fords <Sabrina.Fords@xxxxxxxxxx>
Date: Wed, 9 Jan 2002 15:28:43 -0000
domparser sample

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.