FWIW you can work out the type of the return value from the XPath
expression. Here are some examples.

//server_request/server/weblogic/internal
the above expression will always return zero, 1 or more Elements, since the
last thing on the path expression is an element.

//server_request/server/weblogic/internal/@foo
the above will always return zero, 1 or more Attributes, since the last
thing on the path expression is an attribute

//server_request/server/weblogic/internal/text()
the above will always return zero, 1 or more Text nodes

/
the above will always return 1 Document

If the selectNodes() method is used then a List will be returned containing
the number of nodes described above. If the selectSingleNode() call is used
and an XPath results in more than one node being found, the first node is
returned.

James
----- Original Message -----
From: "Peter Schaefer" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, October 16, 2001 8:35 AM
Subject: Fwd: [dom4j-user] Adding a node to the middle of a pre-existing DOM


> Hi Doug,
> if you are sure, that "internal" is an element, I think you can try the
> type-cast
>
> Element wanted = (Element)
> selectSingleNode("//server_request/server/weblogic/internal");
>
> Hope it helps
> Pete
>
>
>
> >X-MS-Has-Attach:
> >X-MS-TNEF-Correlator:
> >Thread-Topic: Adding a node to the middle of a pre-existing DOM
> >Thread-Index: AcFVwQxQQvYgX23ERXKkNMIOclhiMQ==
> >From: "Doug Hoppes" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Subject: [dom4j-user] Adding a node to the middle of a pre-existing DOM
> >Sender: [EMAIL PROTECTED]
> >X-BeenThere: [EMAIL PROTECTED]
> >X-Mailman-Version: 2.0.5
> >List-Help: <mailto:[EMAIL PROTECTED]?subject=help>
> >List-Post: <mailto:[EMAIL PROTECTED]>
> >List-Subscribe:
<https://lists.sourceforge.net/lists/listinfo/dom4j-user>,
> >
<mailto:[EMAIL PROTECTED]?subject=subscribe>
> >List-Id: mail list for users of DOM4J <dom4j-user.lists.sourceforge.net>
> >List-Unsubscribe:
<https://lists.sourceforge.net/lists/listinfo/dom4j-user>,
> >
<mailto:[EMAIL PROTECTED]?subject=unsubscribe>
> >List-Archive: <http://www.geocrawler.com/redir-sf.php3?list=dom4j-user>
> >X-Original-Date: Mon, 15 Oct 2001 17:33:37 -0400
> >Date: Mon, 15 Oct 2001 17:33:37 -0400
> >X-AntiVirus: OK (checked by AntiVir Version 6.10.0.11)
> >
> >Hi all,
> >
> >     Just started playing with Dom4J and pretty impressed with it, so
far.
> > Question: I have a extremely large Xml object where I want to add an
> > element to the middle of the Dom tree.  What's the most efficient way of
> > doing this?
> >
> >For example, I want to create an element called
> ><server_address>192.10.20.41</server_address> (where 192.10.20.41 is the
> >text node) to <server_request><server><weblogic><internal>....
> >I was trying to use the
> >selectSingleNode("//server_request/server/weblogic/internal") to get a
> >Node() and use the addElement(), but the Node class doesn't have the
> >addElement() method.
> >
> >Could someone post the code for creating an element in the middle of a
Xml
> >Dom if I know what the XPath is to the parent element?
> >
> >Any help is appreciated.
> >
> >Doug Hoppes
>
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to