The workaround for the whitespace is to trim() the resulting String;
if (textnode.hasChildNodes()) {
String textnodeContent =
textnode.getFirstChild().getNodeValue();
String cleanText = textnodeContent.trim();
}
This removes the whitespaces.
-----Original Message-----
From: Igor PARTL [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 21 November 2001 3:53 a.m.
To: Xerces-J-User
Subject: Re: whitespaceIgnoring (on/off)
Hi!
On Mon, Nov 19, 2001 at 01:45:01PM +1300, Craig Collings wrote:
Thanks a lot for your answer.
> But remember... Once you have a DOM from the parser, the
> nodevalue of the element is NOT 'Hey!' or '\n Hey \n'. In fact the
> direct nodevalue of any Element is null. (I assume we are using
> org.apache.dom)
Jepp, so it is.
> The text that we would think is the nodevalue of an element is held
> as the nodevalue of a Text node which is a child of the Element. So
> we have to get a NodeList from Element, iterate thru it till we find
> a (non-whitespace) Text node and get the nodeValue of textnode.
So I have done.
Node textnode = ....;
// <xml>
// Hey!
// </xml>
if (textnode.hasChildNodes()) {
// Ok, I know, that there is a node, but this is the correct and
// safe way
String textnodeContent = textnode.getFirstChild().getNodeValue();
// The FirstChild is the #TextNode
}
And the result is: '\n Hey\n' - Grgggh!
I have no idea, what's going wrong...
Reading the API shows me a method 'ignorableWhitspace(int)' in
DOMParser; this seems to be a methos for ... But for what. I have noxi
idea.
> Which is all very annoying when all we want is the text from a tag.
Igor PARTL
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]