Hi!
I'm trying to add a element after another element if the element is present
(the element should be present, if present, as the first element). The code
I run is:
XPath xp = DocumentHelper.createXPath("/*/header");
Node n = xp.selectSingleNode(getDocMain());
if(n != null)
{
int headerIndex = getDocMain().indexOf(n);
doc.content().add(headerIndex + 1, elemToAdd);
}
else
{
doc.content().add(0, elemToAdd);
}
doc is ofcourse a Document and elemToAdd is a element (not yet connected to
a Document)...
When running this (and n ends up not being null) the result of headerIndex
is -1. This can't be right since I just picked up the node to find the index
for from the document???!!!
With headerIndex -1 and exception is thrown in the next row, but not
indexOutOfBounce exception as expected but instead a:
org.dom4j.IllegalAddException: This list must contain instances of Node.
Invalid
type: se.posten.logistik.applications.cr.xml.XMLCRDataElement@228362
at
org.dom4j.tree.ContentListFacade.asNode(ContentListFacade.java:154)
at org.dom4j.tree.ContentListFacade.add(ContentListFacade.java:59)
at
se.posten.logistik.applications.cr.xml.XMLCRProtocollDocument.addCRDa
taElementToRoot(XMLCRProtocollDocument.java:48)
at
se.posten.logistik.applications.cr.xml.XMLCollectionRequestDocument.g
etDocument(XMLCollectionRequestDocument.java:60)
at
se.posten.logistik.applications.cr.vl.VLCRRHTrans.performActionList(V
LCRRHTrans.java:155)
at
se.posten.logistik.applications.cr.vl.VLCRBase.performAction(VLCRBase
.java:105)
at
se.posten.logistik.applications.cr.CRServlet.doGet(CRServlet.java:84)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at com.caucho.server.http.Invocation.service(Invocation.java:296)
at
com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:1
21)
at
com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:238
)
at
com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:
157)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)
Packet utan id.
org.dom4j.IllegalAddException: This list must contain instances of Node.
Invalid
type: se.posten.logistik.applications.cr.xml.XMLCRDataElement@3936e1
at
org.dom4j.tree.ContentListFacade.asNode(ContentListFacade.java:154)
at org.dom4j.tree.ContentListFacade.add(ContentListFacade.java:59)
at
se.posten.logistik.applications.cr.xml.XMLCRProtocollDocument.addCRDa
taElementToRoot(XMLCRProtocollDocument.java:48)
at
se.posten.logistik.applications.cr.xml.XMLCollectionRequestDocument.g
etDocument(XMLCollectionRequestDocument.java:60)
at
se.posten.logistik.applications.cr.vl.VLCRRHTrans.performActionList(V
LCRRHTrans.java:155)
at
se.posten.logistik.applications.cr.vl.VLCRBase.performAction(VLCRBase
.java:105)
at
se.posten.logistik.applications.cr.CRServlet.doGet(CRServlet.java:84)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at com.caucho.server.http.Invocation.service(Invocation.java:296)
at
com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:1
21)
at
com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:238
)
at
com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:
157)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)
I really don't understands what happens....
Cheers Christian
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user