Java 类org.w3c.dom.CharacterData 实例源码

项目:rapla-parser    文件:DataImporter.java   
private static String getTime(NodeList aChildren) {
    // If no event is provided, appointment is whole working day
    String timeData, time = "99:99-99:99";
    Node firstElNode = aChildren.item(0);
    // If no event is provided, event is whole working day
    if (firstElNode.getNodeType() == Node.ELEMENT_NODE) {
        Element el = (Element) firstElNode;
        String tagName  = el.getTagName();
        if (tagName.equals("span") && el.getAttribute("class" ).equals("link")) {
            time = getTime(firstElNode.getChildNodes());
        } else {
            time = "08:00-18:00";
        }
    } else if (firstElNode.getNodeType() == Node.TEXT_NODE){
        timeData = ((CharacterData) firstElNode).getData();
        // Filter   alias  
        time = timeData.substring(0, 5).concat(timeData.substring(6));
    }
    return time;
}
项目:parabuild-ci    文件:DomUtil.java   
/**
 * Extract the textual content from a Node.
 * This is rather like the XPath value of a Node.
 * @param node The node to extract the text from
 * @return The textual value of the node
 */
public static String getText(Node node)
{
    StringBuffer reply = new StringBuffer();

    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
    {
        Node child = children.item(i);

        if ((child instanceof CharacterData && !(child instanceof Comment)) || child instanceof EntityReference)
        {
            reply.append(child.getNodeValue());
        }
        else if (child.getNodeType() == Node.ELEMENT_NODE)
        {
            reply.append(getText(child));
        }
    }

    return reply.toString();
}
项目:openjdk-jdk10    文件:SOAPDocumentImpl.java   
public void registerChildNodes(Node parentNode, boolean deep) {
    if (parentNode.getUserData(SAAJ_NODE) == null) {
        if (parentNode instanceof Element) {
            ElementFactory.createElement(this, (Element) parentNode);
        } else if (parentNode instanceof CharacterData) {
            switch (parentNode.getNodeType()) {
                case CDATA_SECTION_NODE:
                    new CDATAImpl(this, (CharacterData) parentNode);
                    break;
                case COMMENT_NODE:
                    new SOAPCommentImpl(this, (CharacterData) parentNode);
                    break;
                case TEXT_NODE:
                    new SOAPTextImpl(this, (CharacterData) parentNode);
                    break;
            }
        }
    }
    if (deep) {
        NodeList nodeList = parentNode.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node nextChild = nodeList.item(i);
            registerChildNodes(nextChild, true);
        }
    }
}
项目:dwr    文件:DomUtil.java   
/**
 * Extract the textual content from a Node.
 * This is rather like the XPath value of a Node.
 * @param node The node to extract the text from
 * @return The textual value of the node
 */
public static String getText(Node node)
{
    StringBuffer reply = new StringBuffer();

    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
    {
        Node child = children.item(i);

        if ((child instanceof CharacterData && !(child instanceof Comment)) || child instanceof EntityReference)
        {
            reply.append(child.getNodeValue());
        }
        else if (child.getNodeType() == Node.ELEMENT_NODE)
        {
            reply.append(getText(child));
        }
    }

    return reply.toString();
}
项目:allure2    文件:XmlElement.java   
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public XmlElement(final Element element) {
    this.name = element.getNodeName();
    final NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        final Node item = attributes.item(i);
        this.attributes.put(item.getNodeName(), item.getNodeValue());
    }

    final StringBuilder textValue = new StringBuilder();
    final NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        final Node node = children.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            this.children.add(new XmlElement((Element) node));
        }
        if (node.getNodeType() == Node.TEXT_NODE) {
            textValue.append(node.getNodeValue());
        }
        if (node.getNodeType() == Node.CDATA_SECTION_NODE) {
            textValue.append(((CharacterData) node).getData());
        }
    }
    this.value = textValue.toString();
}
项目:flatworm    文件:DefaultConfigurationReaderImpl.java   
/**
 * Retrieve the {@code CDATA} value from a given Node - noting that the {@code node}'s child nodes will be searched and the first {@code
 * CDATA} tag will be returned.
 *
 * @param node The node that will be searched.
 * @return The {@code CDATA} found as a {@link String} or {@code null} if a {@code CDATA} node was not found.
 */
protected String getChildCDataNodeValue(Node node) {
    String result = null;
    NodeList children = node.getChildNodes();
    if (children != null) {
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
                result = CharacterData.class.cast(child).getData();
                if (result != null) {
                    result = result.trim();
                }
                break;
            }
        }
    }
    return result;
}
项目:sakai    文件:ItemHelperBase.java   
/**
 * Concatenate nodes for xpath
 * @param itemXml
 * @param xpath
 * @return
 */
protected String makeItemNodeText(Item itemXml, String xpath)
{
  //String text = "";
  List nodes = itemXml.selectNodes(xpath);
  Iterator iter = nodes.iterator();

  StringBuilder textbuf = new StringBuilder();   
  while (iter.hasNext())
  {
    Node node = (Node) iter.next();
    Node child = node.getFirstChild();
    if ( (child != null) && child instanceof CharacterData)
    {
      CharacterData cdi = (CharacterData) child;
      textbuf.append(" " + cdi.getData());
    }
  }
  String text = textbuf.toString();
  return text;
}
项目:cosmo    文件:PrincipalPropertySearchReport.java   
private boolean matchText(Element parent,
                          String match) {
    NodeList children = parent.getChildNodes();
    for (int i=0; i<children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element e = (Element) child;
            if (! matchText(e, match)) {
                return false;
            }
        } else if (child.getNodeType() == Node.TEXT_NODE ||
                   child.getNodeType() == Node.CDATA_SECTION_NODE) {
            String data = ((CharacterData) child).getData();
            if (! matchText(data, match)) {
                return false;
            }
        } // else we skip the node
    }
    return true;
}
项目:swift-k    文件:QueuePoller.java   
/**
 * getDataFromElement - Make XML parsing a bit easier 
 * @param e XML Element
 * @return XML data as a String
 */
public static String getDataFromElement(Element e) {
    try {
        Node child = e.getFirstChild();
        if (child instanceof CharacterData) {
            CharacterData cd = (CharacterData) child;
            return cd.getData();
        }
    }

    catch (Exception ex) {
        logger.debug("Error in getDataFromElement");
        logger.debug(ex.getMessage());
        logger.debug(ex.getStackTrace());
    }
    return "";
}
项目:xsylum    文件:XmlSearchable.java   
/**
 * Finds the values for the XPath {@code expression}.
 * 
 * @throws XPathExpressionException if the {@code expression} is invalid
 */
@SuppressWarnings("unchecked")
<V> List<V> valuesInternal(String expression, Converter<V> converter)
    throws XPathExpressionException {
  XPathExpression expr = XPathFactory.newInstance().newXPath().compile(expression);
  NodeList nodeList = (NodeList) expr.evaluate(source, XPathConstants.NODESET);
  if (nodeList.getLength() == 0)
    return Collections.emptyList();

  List<V> values = new ArrayList<V>(nodeList.getLength());
  for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    String value = null;
    if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.ATTRIBUTE_NODE)
      value = node.getNodeValue();
    else if (node.getNodeType() == Node.CDATA_SECTION_NODE)
      value = ((CharacterData) node).getData();

    // Convert value
    if (value != null)
      values.add(converter == null ? (V) value : converter.convert(value));
  }

  return values;
}
项目:jabref    文件:CitationStyle.java   
/**
 * Creates an CitationStyle instance out of the style string
 */
private static Optional<CitationStyle> createCitationStyleFromSource(final String source, final String filename) {
    if ((filename != null) && !filename.isEmpty() && (source != null) && !source.isEmpty()) {
        try {
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(stripInvalidProlog(source)));

            Document doc = db.parse(is);
            NodeList nodes = doc.getElementsByTagName("info");

            NodeList titleNode = ((Element) nodes.item(0)).getElementsByTagName("title");
            String title = ((CharacterData) titleNode.item(0).getFirstChild()).getData();

            return Optional.of(new CitationStyle(filename, title, source));
        } catch (ParserConfigurationException | SAXException | IOException e) {
            LOGGER.error("Error while parsing source", e);
        }
    }
    return Optional.empty();
}
项目:sakai    文件:ItemHelperBase.java   
/**
 * Concatenate nodes for xpath
 * @param itemXml
 * @param xpath
 * @return
 */
protected String makeItemNodeText(Item itemXml, String xpath)
{
  //String text = "";
  List nodes = itemXml.selectNodes(xpath);
  Iterator iter = nodes.iterator();

  StringBuilder textbuf = new StringBuilder();   
  while (iter.hasNext())
  {
    Node node = (Node) iter.next();
    Node child = node.getFirstChild();
    if ( (child != null) && child instanceof CharacterData)
    {
      CharacterData cdi = (CharacterData) child;
      textbuf.append(" " + cdi.getData());
    }
  }
  String text = textbuf.toString();
  return text;
}
项目:zollty-mvc    文件:DefaultDom.java   
@Override
public String getTextValue(Element valueEle) {
    if (valueEle != null) {
        StringBuilder sb = new StringBuilder();
        NodeList nl = valueEle.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node item = nl.item(i);
            if ((item instanceof CharacterData && !(item instanceof Comment))
                    || item instanceof EntityReference) {
                sb.append(item.getNodeValue());
            }
        }
        return sb.toString().trim();
    }
    return null;
}
项目:ibatis-2    文件:SqlStatementParser.java   
private void findAndParseSelectKey(Node node, MappedStatementConfig config) {
  state.getConfig().getErrorContext().setActivity("parsing select key tags");
  boolean foundSQLFirst = false;
  NodeList children = node.getChildNodes();
  for (int i = 0; i < children.getLength(); i++) {
    Node child = children.item(i);
    if (child.getNodeType() == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE) {
      String data = ((CharacterData) child).getData();
      if (data.trim().length() > 0) {
        foundSQLFirst = true;
      }
    } else if (child.getNodeType() == Node.ELEMENT_NODE && "selectKey".equals(child.getNodeName())) {
      Properties attributes = NodeletUtils.parseAttributes(child, state.getGlobalProps());
      String keyPropName = attributes.getProperty("keyProperty");
      String resultClassName = attributes.getProperty("resultClass");
      String type = attributes.getProperty("type");
      config.setSelectKeyStatement(new XMLSqlSource(state, child), resultClassName, keyPropName, foundSQLFirst, type);
      break;
    }
  }
  state.getConfig().getErrorContext().setMoreInfo(null);

}
项目:jrbuilder    文件:ReportUtil.java   
public static String parseTextExpression(Node textElement) {
    if (textElement instanceof CharacterData) {
        return ((CharacterData) textElement).getData().trim();
    } else {
        return "";
    }
}
项目:Monsters_Portal    文件:CalculoFreteCorreio.java   
public static String getCharacterDataFromElement(Element e) {
  Node child = e.getFirstChild();
  if (child instanceof CharacterData) {
    CharacterData cd = (CharacterData) child;
    return cd.getData();
  }
  return "";
}
项目:tangyuan2    文件:XmlNodeWrapper.java   
private String getBodyData(Node child) {
    if (child.getNodeType() == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE) {
        String data = ((CharacterData) child).getData();
        // TODO data = PropertyParser.parse(data, null);
        return data;
    }
    return null;
}
项目:openjdk-jdk10    文件:ElementImpl.java   
protected TextImpl convertToSoapText(CharacterData characterData) {
        final Node soapNode = getSoapDocument().findIfPresent(characterData);
        if (soapNode instanceof TextImpl) {
            return (TextImpl) soapNode;
        } else {
            TextImpl t = null;
            switch (characterData.getNodeType()) {
                case CDATA_SECTION_NODE:
                    t = new CDATAImpl(getSoapDocument(), characterData.getData());
                    break;
                case COMMENT_NODE:
                    t = new SOAPCommentImpl(getSoapDocument(), characterData.getData());
                    break;
                case TEXT_NODE:
                    t = new SOAPTextImpl(getSoapDocument(), characterData.getData());
                    break;
            }
            Node parent = getSoapDocument().find(characterData.getParentNode());
            if (parent != null) {
                parent.replaceChild(t, characterData);
            } // XXX else throw an exception?

            return t;

//            return replaceElementWithSOAPElement(
//                element,
//                (ElementImpl) createElement(NameImpl.copyElementName(element)));
        }
    }
项目:openjdk-jdk10    文件:AbstractCharacterDataTest.java   
@Test
public void testAppendData() throws Exception {
    CharacterData cd = createCharacterData("DOM");
    cd.appendData("2");
    assertEquals(cd.getData(), "DOM2");

}
项目:openjdk-jdk10    文件:AbstractCharacterDataTest.java   
@Test(dataProvider = "data-for-replace-neg")
public void testReplaceDataNeg(String text, int offset, int count, String arg) throws Exception {
    CharacterData cd = createCharacterData(text);
    try {
        cd.replaceData(offset, count, arg);
        fail(DOMEXCEPTION_EXPECTED);
    } catch (DOMException e) {
        assertEquals(e.code, INDEX_SIZE_ERR);
    }
}
项目:openjdk-jdk10    文件:AbstractCharacterDataTest.java   
@Test(dataProvider = "data-for-insert-neg")
public void testInsertDataNeg(String text, int offset) throws Exception {
    CharacterData cd = createCharacterData(text);
    try {
        cd.insertData(offset, "TEST");
        fail(DOMEXCEPTION_EXPECTED);
    } catch (DOMException e) {
        assertEquals(e.code, INDEX_SIZE_ERR);
    }
}
项目:openjdk-jdk10    文件:AbstractCharacterDataTest.java   
@Test(dataProvider = "data-for-substring-neg")
public void testSubstringDataNeg(String text, int offset, int count) throws Exception {
    CharacterData cd = createCharacterData(text);
    try {
        cd.substringData(offset, count);
        fail(DOMEXCEPTION_EXPECTED);
    } catch (DOMException e) {
        assertEquals(e.code, INDEX_SIZE_ERR);
    }

}
项目:openjdk9    文件:AbstractCharacterDataTest.java   
@Test
public void testAppendData() throws Exception {
    CharacterData cd = createCharacterData("DOM");
    cd.appendData("2");
    assertEquals(cd.getData(), "DOM2");

}
项目:openjdk9    文件:AbstractCharacterDataTest.java   
@Test(dataProvider = "data-for-replace-neg")
public void testReplaceDataNeg(String text, int offset, int count, String arg) throws Exception {
    CharacterData cd = createCharacterData(text);
    try {
        cd.replaceData(offset, count, arg);
        fail(DOMEXCEPTION_EXPECTED);
    } catch (DOMException e) {
        assertEquals(e.code, INDEX_SIZE_ERR);
    }
}
项目:openjdk9    文件:AbstractCharacterDataTest.java   
@Test(dataProvider = "data-for-insert-neg")
public void testInsertDataNeg(String text, int offset) throws Exception {
    CharacterData cd = createCharacterData(text);
    try {
        cd.insertData(offset, "TEST");
        fail(DOMEXCEPTION_EXPECTED);
    } catch (DOMException e) {
        assertEquals(e.code, INDEX_SIZE_ERR);
    }
}
项目:openjdk9    文件:AbstractCharacterDataTest.java   
@Test(dataProvider = "data-for-substring-neg")
public void testSubstringDataNeg(String text, int offset, int count) throws Exception {
    CharacterData cd = createCharacterData(text);
    try {
        cd.substringData(offset, count);
        fail(DOMEXCEPTION_EXPECTED);
    } catch (DOMException e) {
        assertEquals(e.code, INDEX_SIZE_ERR);
    }

}
项目:MybatisCode    文件:XNode.java   
private String getBodyData(Node child) {
  if (child.getNodeType() == Node.CDATA_SECTION_NODE
      || child.getNodeType() == Node.TEXT_NODE) {
    String data = ((CharacterData) child).getData();
    data = PropertyParser.parse(data, variables);
    return data;
  }
  return null;
}
项目:JavaExamples    文件:CurrencyReader.java   
private String getCharacterDataFromElement(Element e) {
    try {
        Node child = e.getFirstChild();
        if (child instanceof CharacterData) {
            CharacterData cd = (CharacterData) child;
            return cd.getData();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return "";
}
项目:spring4-understanding    文件:DomUtils.java   
/**
 * Extracts the text value from the given DOM element, ignoring XML comments.
 * <p>Appends all CharacterData nodes and EntityReference nodes into a single
 * String value, excluding Comment nodes. Only exposes actual user-specified
 * text, no default values of any kind.
 * @see CharacterData
 * @see EntityReference
 * @see Comment
 */
public static String getTextValue(Element valueEle) {
    Assert.notNull(valueEle, "Element must not be null");
    StringBuilder sb = new StringBuilder();
    NodeList nl = valueEle.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node item = nl.item(i);
        if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
            sb.append(item.getNodeValue());
        }
    }
    return sb.toString();
}
项目:cs509    文件:Flights.java   
/**
 * Retrieve character data from an element if it exists
 * 
 * @param e is the DOM Element to retrieve character data from
 * @return the character data as String [possibly empty String]
 */
private static String getCharacterDataFromElement (Element e) {
    Node child = e.getFirstChild();
    if (child instanceof CharacterData) {
        CharacterData cd = (CharacterData) child;
        return cd.getData();
      }
      return "";
}
项目:cs509    文件:Airports.java   
/**
 * Retrieve character data from an element if it exists
 * 
 * @param e is the DOM Element to retrieve character data from
 * @return the character data as String [possibly empty String]
 */
private static String getCharacterDataFromElement (Element e) {
    Node child = e.getFirstChild();
    if (child instanceof CharacterData) {
        CharacterData cd = (CharacterData) child;
        return cd.getData();
      }
      return "";
}
项目:cs509    文件:Airplanes.java   
/**
 * Retrieve character data from an element if it exists
 * 
 * @param e is the DOM Element to retrieve character data from
 * @return the character data as String [possibly empty String]
 */
private static String getCharacterDataFromElement (Element e) {
    Node child = e.getFirstChild();
    if (child instanceof CharacterData) {
        CharacterData cd = (CharacterData) child;
        return cd.getData();
      }
      return "";
}
项目:mybatis    文件:XNode.java   
private String getBodyData(Node child) {
  if (child.getNodeType() == Node.CDATA_SECTION_NODE
      || child.getNodeType() == Node.TEXT_NODE) {
    String data = ((CharacterData) child).getData();
    data = PropertyParser.parse(data, variables);
    return data;
  }
  return null;
}
项目:JHelioviewer-SWHV    文件:XMLMetaDataContainer.java   
private String getValueFromXML(String key) {
    Element line = (Element) meta.getElementsByTagName(key).item(0);
    if (line == null)
        return null;

    Node child = line.getFirstChild();
    if (child instanceof CharacterData)
        return ((CharacterData) child).getData();
    return null;
}
项目:tangyuan    文件:XmlNodeWrapper.java   
private String getBodyData(Node child) {
    if (child.getNodeType() == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE) {
        String data = ((CharacterData) child).getData();
        // TODO data = PropertyParser.parse(data, null);
        return data;
    }
    return null;
}
项目:BridgePG-Java    文件:ApiCall.java   
public static String getCharacterDataFromElement(Element e) {
  Node child = e.getFirstChild();
  if (child instanceof CharacterData) {
     CharacterData cd = (CharacterData) child;
     return cd.getData();
  }

  return"" ;
}
项目:spring    文件:DomUtils.java   
/**
 * Extracts the text value from the given DOM element, ignoring XML comments.
 * <p>Appends all CharacterData nodes and EntityReference nodes into a single
 * String value, excluding Comment nodes. Only exposes actual user-specified
 * text, no default values of any kind.
 * @see CharacterData
 * @see EntityReference
 * @see Comment
 */
public static String getTextValue(Element valueEle) {
    Assert.notNull(valueEle, "Element must not be null");
    StringBuilder sb = new StringBuilder();
    NodeList nl = valueEle.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node item = nl.item(i);
        if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
            sb.append(item.getNodeValue());
        }
    }
    return sb.toString();
}
项目:gvnix1    文件:DomUtils.java   
/**
 * Extract the text value from the given DOM element, ignoring XML comments.
 * <p>
 * Appends all CharacterData nodes and EntityReference nodes into a single
 * String value, excluding Comment nodes.
 * 
 * @see CharacterData
 * @see EntityReference
 * @see Comment
 */
public static String getTextValue(final Element valueElement) {
    Validate.notNull(valueElement, "Element must not be null");
    final StringBuilder sb = new StringBuilder();
    final NodeList nl = valueElement.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        final Node item = nl.item(i);
        if (item instanceof CharacterData && !(item instanceof Comment)
                || item instanceof EntityReference) {
            sb.append(item.getNodeValue());
        }
    }
    return sb.toString();
}
项目:javify    文件:DomConsumer.java   
public void characters (char ch [], int start, int length)
throws SAXException
{
    // we can't create populated entity ref nodes using
    // only public DOM APIs (they've got to be readonly
    // at creation time)
    if (currentEntity != null)
        return;

    Node        lastChild = top.getLastChild ();

    // merge consecutive text or CDATA nodes if appropriate.
    if (lastChild instanceof Text) {
        if (consumer.isHidingCDATA ()
                // consecutive Text content ... always merge
                || (!inCDATA
                    && !(lastChild instanceof CDATASection))
                // consecutive CDATASection content ... don't
                // merge between sections, only within them
                || (inCDATA && mergeCDATA
                    && lastChild instanceof CDATASection)
                    ) {
            CharacterData       last = (CharacterData) lastChild;
            String              value = new String (ch, start, length);

            last.appendData (value);
            return;
        }
    }
    if (inCDATA && !consumer.isHidingCDATA ()) {
        top.appendChild (createText (true, ch, start, length));
        mergeCDATA = true;
    } else
        top.appendChild (createText (false, ch, start, length));
}
项目:discoursedb-core    文件:HabworldsConverterService.java   
private String getCharacterDataFromElement(Element e) {
    Node child = e.getFirstChild();
    if (child instanceof CharacterData) {
        CharacterData cd = (CharacterData) child;
        return cd.getData();
    }
    return "?";
}