Esempio n. 1
0
  /**
   * Find the first direct child with a given attribute.
   *
   * @param parent
   * @param elemName name of the element, or null for any
   * @param attName attribute we're looking for
   * @param attVal attribute value or null if we just want any
   */
  public static Node findChildWithAtt(Node parent, String elemName, String attName, String attVal) {

    Node child = DomUtil.getChild(parent, Node.ELEMENT_NODE);
    if (attVal == null) {
      while (child != null
          && (elemName == null || elemName.equals(child.getNodeName()))
          && DomUtil.getAttribute(child, attName) != null) {
        child = getNext(child, elemName, Node.ELEMENT_NODE);
      }
    } else {
      while (child != null
          && (elemName == null || elemName.equals(child.getNodeName()))
          && !attVal.equals(DomUtil.getAttribute(child, attName))) {
        child = getNext(child, elemName, Node.ELEMENT_NODE);
      }
    }
    return child;
  }
Esempio n. 2
0
  /** Get the trimed text content of a node or null if there is no text */
  public static String getContent(Node n) {
    if (n == null) return null;
    Node n1 = DomUtil.getChild(n, Node.TEXT_NODE);

    if (n1 == null) return null;

    String s1 = n1.getNodeValue();
    return s1.trim();
  }
Esempio n. 3
0
 /** Set or replace the text value */
 public static void setText(Node node, String val) {
   Node chld = DomUtil.getChild(node, Node.TEXT_NODE);
   if (chld == null) {
     Node textN = node.getOwnerDocument().createTextNode(val);
     node.appendChild(textN);
     return;
   }
   // change the value
   chld.setNodeValue(val);
 }