Package org.w3c.dom

Examples of org.w3c.dom.CharacterData


    }
    return element;
  }

  private void setElementValue(Element element, Object value) {
    CharacterData data = null;

    Element prop = element;

    if (value instanceof Collection) {
      Iterator items = ((Collection) value).iterator();
      while (items.hasNext()) {
        Document valdoc = (Document) items.next();
        NodeList list = valdoc.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
          Node newNode = element.getOwnerDocument().importNode(list.item(i), true);
          element.appendChild(newNode);
        }
      }
    } else if (value instanceof Document) {
      Document valdoc = (Document) value;
      Node lastChild = valdoc.getLastChild();
      NodeList list = lastChild.getChildNodes();
      for (int i = 0; i < list.getLength(); i++) {
        Node newNode = element.getOwnerDocument().importNode(list.item(i), true);
        element.appendChild(newNode);
      }
    } else if (value instanceof Element) {
      Node newNode = element.getOwnerDocument().importNode((Element) value, true);
      element.appendChild(newNode);
    } else {
      // Find text child element
      NodeList texts = prop.getChildNodes();
      if (texts.getLength() == 1) {
        Node child = texts.item(0);
        if (child instanceof CharacterData) {
          // Use existing text.
          data = (CharacterData) child;
        } else {
          // Remove non-text, add text.
          prop.removeChild(child);
          Text text = prop.getOwnerDocument().createTextNode(String.valueOf(value));
          prop.appendChild(text);
          data = text;
        }
      } else if (texts.getLength() > 1) {
        // Remove all, add text.
        for (int i = texts.getLength() - 1; i >= 0; i--) {
          prop.removeChild(texts.item(i));
        }
        Text text = prop.getOwnerDocument().createTextNode(String.valueOf(value));
        prop.appendChild(text);
        data = text;
      } else {
        // Add text.
        Text text = prop.getOwnerDocument().createTextNode(String.valueOf(value));
        prop.appendChild(text);
        data = text;
      }
      data.setData(String.valueOf(value));
    }

    // Set type attribute
    //prop.setAttribute("type", value == null ? "null" : value.getClass().getName());
View Full Code Here


    if (parentEl == null) {
      return null;
    }
    Node          tempNode = parentEl.getFirstChild();
    StringBuffer  strBuf   = new StringBuffer();
    CharacterData charData;

    while (tempNode != null) {
      switch (tempNode.getNodeType()) {
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE : charData = (CharacterData)tempNode;
                                       strBuf.append(charData.getData());
                                       break;
      }
      tempNode = tempNode.getNextSibling();
    }
    return strBuf.toString();
View Full Code Here

            final Node node = nodes.item( i );
            if( node instanceof Element ) {
                final Configuration child = toConfiguration( (Element)node );
                configuration.addChild( child );
            } else if( node instanceof CharacterData ) {
                final CharacterData data = (CharacterData)node;
                content += data.getData();
                flag = true;
            }
        }

        if( flag ) {
View Full Code Here

    if (parentEl == null) {
      return null;
    }
    Node          tempNode = parentEl.getFirstChild();
    StringBuffer  strBuf   = new StringBuffer();
    CharacterData charData;

    while (tempNode != null) {
      switch (tempNode.getNodeType()) {
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE : charData = (CharacterData)tempNode;
                                       strBuf.append(charData.getData());
                                       break;
      }
      tempNode = tempNode.getNextSibling();
    }
    return strBuf.toString();
View Full Code Here

        if (parentEl == null) {
            return null;
        }
        Node tempNode = parentEl.getFirstChild();
        StringBuffer strBuf = new StringBuffer();
        CharacterData charData;

        while (tempNode != null) {
            switch (tempNode.getNodeType()) {
                case Node.TEXT_NODE :
                case Node.CDATA_SECTION_NODE:
                    charData = (CharacterData) tempNode;
                    strBuf.append(charData.getData());
                    break;
            }
            tempNode = tempNode.getNextSibling();
        }
        return strBuf.toString();
View Full Code Here

    if (parentEl == null) {
      return null;
    }
    Node          tempNode = parentEl.getFirstChild();
    StringBuffer  strBuf   = new StringBuffer();
    CharacterData charData;

    while (tempNode != null) {
      switch (tempNode.getNodeType()) {
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE : charData = (CharacterData)tempNode;
                                       strBuf.append(charData.getData());
                                       break;
      }
      tempNode = tempNode.getNextSibling();
    }
    return strBuf.toString();
View Full Code Here

    if (parentEl == null) {
      return null;
    }
    Node          tempNode = parentEl.getFirstChild();
    StringBuffer  strBuf   = new StringBuffer();
    CharacterData charData;

    while (tempNode != null) {
      switch (tempNode.getNodeType()) {
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE : charData = (CharacterData)tempNode;
                                       strBuf.append(charData.getData());
                                       break;
      }
      tempNode = tempNode.getNextSibling();
    }
    return strBuf.toString();
View Full Code Here

                final Configuration child = toConfiguration( (Element)node );
                configuration.addChild( child );
            }
            else if( node instanceof CharacterData )
            {
                final CharacterData data = (CharacterData)node;
                content += data.getData();
                flag = true;
            }
        }

        if( flag )
View Full Code Here

    if (parentEl == null) {
      return null;
    }
    Node          tempNode = parentEl.getFirstChild();
    StringBuffer  strBuf   = new StringBuffer();
    CharacterData charData;

    while (tempNode != null) {
      switch (tempNode.getNodeType()) {
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE : charData = (CharacterData)tempNode;
                                       strBuf.append(charData.getData());
                                       break;
      }
      tempNode = tempNode.getNextSibling();
    }
    return strBuf.toString();
View Full Code Here

    NodeList list = rootElement.getElementsByTagName(tagname);
    if (list.getLength() > 0) {
      Element element = (Element)list.item(0);
      Node child = element.getFirstChild();
      if (child instanceof CharacterData) {
        CharacterData cd = (CharacterData) child;
        return cd.getData();
      }
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of org.w3c.dom.CharacterData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.