You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Robbie Baldock <ro...@realise.com> on 2000/08/31 18:05:34 UTC
Extracting the contents of elements
This is probably a stupid question but then I am a newbie...
How do I actually extract the "value" of an element (ie: the stuff between
the tags)?
For example, I would have thought that, given a Document objDocument, to get
the value of the content_HREF element from this bit of XML:
<content_HREF>http://www.mysite.com/</content_HREF>
I would do something like this:
NodeList objContentHREF = objDocument.getElementsByTagName("content_HREF");
String strURL = objContentHREF.item(0).getNodeValue();
But this returns null.
Robbie Baldock
RE: Extracting the contents of elements
Posted by Ed Staub <es...@mediaone.net>.
Extracting the contents of elementsNope!
The content of the element is contained in one or more child Text nodes.
To flatten adjacent text nodes to a single node, use normalize(), see
http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-745549614. Note
that it works recursively; you don't have to call it a lot. For the values
returned by getNodeValue, see the table in
http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1950641247.
-Ed Staub
-----Original Message-----
From: Robbie Baldock [mailto:robbie@realise.com]
Sent: Thursday, August 31, 2000 12:06 PM
To: xerces-j-dev@xml.apache.org
Subject: Extracting the contents of elements
This is probably a stupid question but then I am a newbie...
How do I actually extract the "value" of an element (ie: the stuff between
the tags)?
For example, I would have thought that, given a Document objDocument, to
get the value of the content_HREF element from this bit of XML:
<content_HREF>http://www.mysite.com/</content_HREF>
I would do something like this:
NodeList objContentHREF =
objDocument.getElementsByTagName("content_HREF");
String strURL = objContentHREF.item(0).getNodeValue();
But this returns null.
Robbie Baldock