What does the stack trace from the exception look like? Gary
> -----Original Message----- > From: Al Byers [mailto:[EMAIL PROTECTED] > Sent: Thursday, January 17, 2002 3:15 AM > To: [EMAIL PROTECTED] > Subject: Returning foreign nodesets from an extension call > > > I read in the documentation that one uses the NodeSet class > to return a > nodeset to the transformer if you want to change the input > list. Is it > possible to change the contents or attributes of the input > nodelist and send > it back. I have had no luck. When I try to add an attribute > or a new element > to the input nodeset, it bombs. Here is my scratch code: > > public NodeSet testext2(NodeList pNodeList){ > int i=0; > NodeSet lNodeSet3 = new NodeSet(); > Node lNode = (Node)pNodeList.item(0); > NodeList lNL2 = lNode.getChildNodes(); > int iLen = lNL2.getLength(); > Node lNode2 = null; > Element lElem4 = null; > Attr lAttr = null; > int iType; > for( i=0; i<iLen; i++) > { > lNode2 = (Node)lNL2.item(i); > iType = lNode2.getNodeType(); > if(iType == Node.ELEMENT_NODE) > { > lElem4 = (Element)lNode2; > // > // This code works if the following line is > commented out. > // > lElem4.setAttribute("test", "junk"); > lNodeSet3.addNode(lElem4); > } > System.out.println("Size:" + lNodeSet3.size()); > } > > Node lNode4 = null; > Document lDocOut = _DBuilder.newDocument(); > Document lDocIn = lNode.getOwnerDocument(); > Element lElem = lDocOut.createElement("test"); > Element lElem2 = lDocOut.createElement("test2"); > Element lElem3 = lDocOut.createElement("test3"); > lElem.appendChild(lElem2); > lElem.appendChild(lElem3); > lDocOut.appendChild(lElem); > //Node lNodeImported = lDocIn.importNode(lElem, true); > //lNode.appendChild(lNodeImported); > NodeSet lNodeSet4 = new NodeSet(); > Element lElemDoc = lDocOut.getDocumentElement(); > NodeList lNL4 = lElemDoc.getChildNodes(); > iLen = lNL2.getLength(); > lNode2 = null; > for( i=0; i<iLen; i++) > { > lNode2 = (Node)lNL4.item(i); > if(lNode2 != null ) > { > iType = lNode2.getNodeType(); > if(iType == Node.ELEMENT_NODE) > { > // > // The following line throws an exception > // > lNode4 = lDocIn.importNode(lNode2,true); > lNodeSet4.addNode(lNode4); > } > System.out.println("Size:" + lNodeSet4.size()); > } > } > > return lNodeSet3; // or lNodeSet4 > } > > > > > _________________________________________________________________ > Join the world's largest e-mail service with MSN Hotmail. > http://www.hotmail.com >
