Title: How To remove WhiteSpace
Hi,
I had the same problem.
First I though setting the feature    http://apache.org/xml/features/dom/include-ignorable-whitespace to false would solve the problem but then you always need a grammar.
 
Now I just traverse the tree and remove all empty textnodes :
 
private static void removeEmptyTextNodes(Element node) {
    Node el = node.getFirstChild();
    while (el != null) {
      Node next = el.getNextSibling();
      if (el.getNodeType() == Node.TEXT_NODE) {
        String str = el.getNodeValue().trim();
        if (str.equals("")) {
          node.removeChild(el);
        }
      } else {
        if (el.getNodeType() == Node.ELEMENT_NODE) {
          removeEmptyTextNodes((Element)el);
        }
      }
      el = next;
    }
  }
 
-----Original Message-----
From: Harikrishna_B [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 13, 2002 8:35 AM
To: [EMAIL PROTECTED]
Subject: How To remove WhiteSpace

Hello All,
    I constructed a Dom from an xml file.
    I had counted the number of children for the rootnode.
    I am getting #text elements are also the children of root node.
    How to remove this #text?
    This empty element is coming between one element and the other element.


Thanks in Advance,
B.HARIKRISHNA


**************************************************************************
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.

**************************************************************************

Reply via email to