Friday 5 August 2011

Get the trimed text content of a node or null if there is no text

  
import org.w3c.dom.Node;
/**
 *  
 *
 @author Costin Manolache
 */
public class Main {


  /** Get the trimed text content of a node or null if there is no text
   */
  public static String getContent(Node n ) {
      ifn==null return null;
      Node n1=getChild(n, Node.TEXT_NODE);

      ifn1==null return null;

      String s1=n1.getNodeValue();
      return s1.trim();
  }
  /** Get the first direct child with a given type
   */
  public static Node getChildNode parent, int type ) {
      Node n=parent.getFirstChild();
      whilen!=null && type != n.getNodeType() ) {
          n=n.getNextSibling();
      }
      ifn==null return null;
      return n;
  }
}

   
    
  

No comments:

Post a Comment