org.w3c.dom.Text#setNodeValue ( )源码实例Demo

下面列出了org.w3c.dom.Text#setNodeValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: J2SESampleProjectGenerator.java
/**
 * Extract nested text from an element.
 * Currently does not handle coalescing text nodes, CDATA sections, etc.
 * @param parent a parent element
 */
private static void replaceText(Element parent, String name) {
    NodeList l = parent.getChildNodes();
    for (int i = 0; i < l.getLength(); i++) {
        if (l.item(i).getNodeType() == Node.TEXT_NODE) {
            Text text = (Text)l.item(i);
            text.setNodeValue(name);
            return;
        }
    }
}
 
源代码2 项目: netbeans   文件: JavaFXSampleProjectGenerator.java
/**
 * Extract nested text from an element.
 * Currently does not handle coalescing text nodes, CDATA sections, etc.
 * @param parent a parent element
 */
private static void replaceText(Element parent, String name) {
    NodeList l = parent.getChildNodes();
    for (int i = 0; i < l.getLength(); i++) {
        if (l.item(i).getNodeType() == Node.TEXT_NODE) {
            Text text = (Text) l.item(i);
            text.setNodeValue(name);
            return;
        }
    }
}
 
源代码3 项目: oasp4j-ide   文件: XmlHandler.java
/**
 * Resolves the variables within the element's Text and calls
 * {@link #resolveAttributes(NamedNodeMap)}
 * to resolve it's attributes.
 * @param element - element to be resolved.
 */
private void resolveElement(Element element) {
  resolveAttributes(element.getAttributes());
  NodeList nodeList = element.getChildNodes();

  for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node instanceof Text) {
      Text text = (Text) node;
      text.setNodeValue(resolver.resolveVariables(text.getNodeValue()));
    }
  }
}
 
源代码4 项目: commons-configuration   文件: XMLConfiguration.java
/**
 * Updates the node's value if it represents an element node.
 *
 * @param element the element
 * @param value the new value
 */
private void updateElement(final Element element, final Object value)
{
    Text txtNode = findTextNodeForUpdate(element);
    if (value == null)
    {
        // remove text
        if (txtNode != null)
        {
            element.removeChild(txtNode);
        }
    }
    else
    {
        final String newValue = String.valueOf(value);
        if (txtNode == null)
        {
            txtNode = document.createTextNode(newValue);
            if (element.getFirstChild() != null)
            {
                element.insertBefore(txtNode, element.getFirstChild());
            }
            else
            {
                element.appendChild(txtNode);
            }
        }
        else
        {
            txtNode.setNodeValue(newValue);
        }
    }
}
 
源代码5 项目: sakai   文件: ASIBaseClass.java
/**
 *
 *
 * @param xpath
 * @param fieldlabel
 */
protected void createFieldentry(String xpath, String fieldlabel)
{
  if(log.isDebugEnabled())
  {
    log.debug(
      "createFieldentry(String " + xpath + ", String " + fieldlabel + ")");
  }

  try
  {
    List qtimetadataNodes = this.selectNodes(xpath);
    if(qtimetadataNodes.size() > 0)
    {
      Node qtimetadataNode = (Node) qtimetadataNodes.get(0);
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document newDocument = db.newDocument();

      Element qtimetadataField =
        newDocument.createElement(QTIConstantStrings.QTIMETADATAFIELD);
      Element fieldlabelElement =
        newDocument.createElement(QTIConstantStrings.FIELDLABEL);
      Element fieldentryElement =
        newDocument.createElement(QTIConstantStrings.FIELDENTRY);

      Text fieldlabelText =
        newDocument.createTextNode(QTIConstantStrings.FIELDLABEL);
      fieldlabelText.setNodeValue(fieldlabel);
      fieldlabelElement.appendChild(fieldlabelText);

      Text fieldentryText =
        newDocument.createTextNode(QTIConstantStrings.FIELDENTRY);
      fieldentryElement.appendChild(fieldentryText);

      Node importedFLE =
        qtimetadataField.getOwnerDocument().importNode(
          fieldlabelElement, true);
      Node importedFEE =
        qtimetadataField.getOwnerDocument().importNode(
          fieldentryElement, true);
      qtimetadataField.appendChild(importedFLE);
      qtimetadataField.appendChild(importedFEE);
      Node importedField =
        qtimetadataNode.getOwnerDocument().importNode(qtimetadataField, true);
      qtimetadataNode.appendChild(importedField);
    }
  }
  catch(ParserConfigurationException pce) {
  	log.error("Exception thrown from createFieldentry()" + pce.getMessage(), pce);
  }
  catch(Exception ex)
  {
    log.error(ex.getMessage(), ex);
  }
}
 
源代码6 项目: sakai   文件: ASIBaseClass.java
/**
 *
 *
 * @param xpath
 * @param fieldlabel
 */
protected void createFieldentry(String xpath, String fieldlabel)
{
  if(log.isDebugEnabled())
  {
    log.debug(
      "createFieldentry(String " + xpath + ", String " + fieldlabel + ")");
  }

  try
  {
    List qtimetadataNodes = this.selectNodes(xpath);
    if(qtimetadataNodes.size() > 0)
    {
      Node qtimetadataNode = (Node) qtimetadataNodes.get(0);
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document newDocument = db.newDocument();

      Element qtimetadataField =
        newDocument.createElement(QTIConstantStrings.QTIMETADATAFIELD);
      Element fieldlabelElement =
        newDocument.createElement(QTIConstantStrings.FIELDLABEL);
      Element fieldentryElement =
        newDocument.createElement(QTIConstantStrings.FIELDENTRY);

      Text fieldlabelText =
        newDocument.createTextNode(QTIConstantStrings.FIELDLABEL);
      fieldlabelText.setNodeValue(fieldlabel);
      fieldlabelElement.appendChild(fieldlabelText);

      Text fieldentryText =
        newDocument.createTextNode(QTIConstantStrings.FIELDENTRY);
      fieldentryElement.appendChild(fieldentryText);

      Node importedFLE =
        qtimetadataField.getOwnerDocument().importNode(
          fieldlabelElement, true);
      Node importedFEE =
        qtimetadataField.getOwnerDocument().importNode(
          fieldentryElement, true);
      qtimetadataField.appendChild(importedFLE);
      qtimetadataField.appendChild(importedFEE);
      Node importedField =
        qtimetadataNode.getOwnerDocument().importNode(qtimetadataField, true);
      qtimetadataNode.appendChild(importedField);
    }
  }
  catch(ParserConfigurationException pce) {
  	log.error("Exception thrown from createFieldentry()" + pce.getMessage(), pce);
  }
  catch(Exception ex)
  {
    log.error(ex.getMessage(), ex);
  }
}