本文整理汇总了Java中org.w3c.dom.CharacterData类的典型用法代码示例。如果您正苦于以下问题:Java CharacterData类的具体用法?Java CharacterData怎么用?Java CharacterData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharacterData类属于org.w3c.dom包,在下文中一共展示了CharacterData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getText
import org.w3c.dom.CharacterData; //导入依赖的package包/类
/**
* 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();
}
示例2: getTime
import org.w3c.dom.CharacterData; //导入依赖的package包/类
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;
}
示例3: registerChildNodes
import org.w3c.dom.CharacterData; //导入依赖的package包/类
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);
}
}
}
示例4: testInsertDataNeg
import org.w3c.dom.CharacterData; //导入依赖的package包/类
@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);
}
}
示例5: XmlElement
import org.w3c.dom.CharacterData; //导入依赖的package包/类
@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();
}
示例6: getChildCDataNodeValue
import org.w3c.dom.CharacterData; //导入依赖的package包/类
/**
* 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;
}
示例7: makeItemNodeText
import org.w3c.dom.CharacterData; //导入依赖的package包/类
/**
* 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;
}
示例8: matchText
import org.w3c.dom.CharacterData; //导入依赖的package包/类
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;
}
示例9: getDataFromElement
import org.w3c.dom.CharacterData; //导入依赖的package包/类
/**
* 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 "";
}
示例10: valuesInternal
import org.w3c.dom.CharacterData; //导入依赖的package包/类
/**
* 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;
}
示例11: createCitationStyleFromSource
import org.w3c.dom.CharacterData; //导入依赖的package包/类
/**
* 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();
}
示例12: getTextValue
import org.w3c.dom.CharacterData; //导入依赖的package包/类
@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;
}
示例13: findAndParseSelectKey
import org.w3c.dom.CharacterData; //导入依赖的package包/类
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);
}
示例14: parseTextExpression
import org.w3c.dom.CharacterData; //导入依赖的package包/类
public static String parseTextExpression(Node textElement) {
if (textElement instanceof CharacterData) {
return ((CharacterData) textElement).getData().trim();
} else {
return "";
}
}
示例15: getCharacterDataFromElement
import org.w3c.dom.CharacterData; //导入依赖的package包/类
public static String getCharacterDataFromElement(Element e) {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
}
return "";
}