Friday 5 August 2011

Get the first child element

  
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Utils {
  /**
   * Get the first child element
   @param parent
   @return
   */
  public static Element getFirstChildElement(Node parent) {
      NodeList childs = parent.getChildNodes();
      for (int i = 0; i < childs.getLength(); i++) {
          Node child = childs.item(i);
          if (child instanceof Element) {
              return (Elementchild;
          }
      }
      return null;
  }

}

   
    
  

No comments:

Post a Comment