Package org.w3c.dom

Examples of org.w3c.dom.CharacterData


                } else if (type == Node.COMMENT_NODE) {
                    node.removeChild(child);
                    len--;
                } else if (type == Node.TEXT_NODE || type == Node.CDATA_SECTION_NODE ) {
                    if (prevTextChild != null) {
                        CharacterData ptc = (CharacterData) prevTextChild;
                        ptc.setData(ptc.getNodeValue() + child.getNodeValue());
                        node.removeChild(child);
                        len--;
                    } else {
                        prevTextChild = child;
                        i++;
View Full Code Here


    StringBuffer buffer = new StringBuffer();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node node = nodeList.item(i);
      if (node instanceof CharacterData) {
        CharacterData characterData = (CharacterData) node;
        buffer.append(characterData.getData());
      }
    }
    return buffer.toString();
  }
View Full Code Here

    }
    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

                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 (obj instanceof SVGElement) {
                SVGElement child = (SVGElement) obj;
                textGraph.appendChild(child);
            } else if (obj instanceof String) {
                String str = (String) obj;
                CharacterData cd = new CharacterDataImpl();
                cd.setData(str);
                textGraph.appendChild(cd);
            }
            //      System.out.println(child);
        }
        /* retrieve properties */
 
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

    StringBuilder text = new StringBuilder();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node node = nodeList.item(i);
      if (node instanceof CharacterData) {
        CharacterData characterData = (CharacterData) node;
        text.append(characterData.getData());
      }
    }
    return text.toString();
  }
View Full Code Here

 
  private boolean hasNewline(Node n) {
    if (n instanceof Comment) {
      return false;
    }
    CharacterData c = (CharacterData) n;
    return (-1) != c.getData().indexOf('\n');
  }
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.