本文整理匯總了Java中org.w3c.dom.Node.TEXT_NODE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Node.TEXT_NODE屬性的具體用法?Java Node.TEXT_NODE怎麽用?Java Node.TEXT_NODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.TEXT_NODE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTextContent
public static String getTextContent(Element element) {
StringBuilder result = new StringBuilder();
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
switch (child.getNodeType()) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
result.append(child.getNodeValue());
break;
default:
break;
}
}
return result.toString();
}
示例2: decorate
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext)
{
BeanDefinitionRegistry registry = parserContext.getRegistry();
BeanDefinition config = registerSpringConfiguratorIfNecessary(registry);
StringBuffer sigtext = new StringBuffer();
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++)
{
Node child = children.item(i);
if (child.getNodeType() != Node.TEXT_NODE && child.getNodeType() != Node.CDATA_SECTION_NODE)
{
log.warn("Ignoring illegal node type: " + child.getNodeType());
continue;
}
sigtext.append(child.getNodeValue());
}
config.getPropertyValues().addPropertyValue("signatures", sigtext.toString());
return definition;
}
示例3: getNormalizedText
public static String getNormalizedText(Node node) {
String res = "";
if (node.hasChildNodes()) {
NodeList nl = node.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
if (nl.item(i).getNodeType() == Node.TEXT_NODE) {
res += nl.item(i).getNodeValue();
} else {
// ignore <SCRIPT> nodes ...
if (!nl.item(i).getNodeName().equalsIgnoreCase("script"))
res += getNormalizedText(nl.item(i));
}
}
}
return res;
}
示例4: hasTextOnlyChildren
/**
* Check if an EntityReference node has Text Only child nodes
*
* @param node
* @return true - Contains text only children
*/
private boolean hasTextOnlyChildren(Node node) {
Node child = node;
if (child == null) {
return false;
}
child = child.getFirstChild();
while (child != null) {
int type = child.getNodeType();
if (type == Node.ENTITY_REFERENCE_NODE) {
return hasTextOnlyChildren(child);
}
else if (type != Node.TEXT_NODE
&& type != Node.CDATA_SECTION_NODE
&& type != Node.ENTITY_REFERENCE_NODE) {
return false;
}
child = child.getNextSibling();
}
return true;
}
示例5: Synonym
protected Synonym(Element element) {
logger.debug("Constructor - entry");
NodeList nodeList = element.getChildNodes();
for (int n = 0; n < nodeList.getLength(); n++) {
Node node = nodeList.item(n);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) node;
if ("RELATION_METADATA".equals(childElement.getNodeName())) {
setRelationMetadata(new RelationMetadata(childElement));
} else {
logger.trace("Unrecognized child node: '" + childElement.getNodeName() + "'");
}
} else if (node.getNodeType() == Node.TEXT_NODE) {
this.setValue(node.getNodeValue());
}
}
NamedNodeMap namedNodeMap = element.getAttributes();
if (namedNodeMap != null) {
for (int a = 0; a < namedNodeMap.getLength(); a++) {
Attr attributeNode = (Attr) namedNodeMap.item(a);
if ("ID".equals(attributeNode.getName())) {
setId(attributeNode.getValue());
} else {
logger.trace("Unrecognized attribute: '" + attributeNode.getName() + "' (" + this.getClass().getName() + ")");
}
}
}
logger.debug("Constructor - exit");
}
示例6: traverseElement
void traverseElement(org.w3c.dom.Element node, StringBuilder sb) {
Node sibling = node.getFirstChild();
while (sibling != null) {
switch (sibling.getNodeType()) {
case Node.ELEMENT_NODE:
traverseElement((Element)sibling, sb);
break;
case Node.TEXT_NODE:
sb.append(((Text)sibling).getData());
}
sibling = sibling.getNextSibling();
}
}
示例7: getBodyData
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;
}
示例8: AbstractFieldListElement
public AbstractFieldListElement(Element element) {
logger.debug("Constructor - entry");
fieldList = new Vector<Field>();
NodeList nodeList = element.getChildNodes();
for (int n = 0; n < nodeList.getLength(); n++) {
Node node = nodeList.item(n);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) node;
if ("FIELD".equals(childElement.getNodeName())) {
addField(new Field(childElement));
} else {
logger.trace("Unrecognized child node: '" + childElement.getNodeName() + "' (" + this.getClass().getName() + ")");
}
} else if ((node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue() != null) && (node.getNodeValue().trim().length() > 0)) {
logger.trace("Unexpected text node (" + this.getClass().getName() + "): '" + node.getNodeValue() + "'");
}
}
NamedNodeMap namedNodeMap = element.getAttributes();
if (namedNodeMap != null) {
for (int a = 0; a < namedNodeMap.getLength(); a++) {
Attr attributeNode = (Attr) namedNodeMap.item(a);
if ("TYPE".equals(attributeNode.getName())) {
setType(attributeNode.getValue());
} else if ("ABBR".equals(attributeNode.getName())) {
setAbbreviation(attributeNode.getValue());
} else {
logger.trace("Unrecognized attribute: '" + attributeNode.getName() + "' (" + this.getClass().getName() + ")");
}
}
}
logger.debug("Constructor - exit");
}
示例9: saveEnclosingAttr
/**
* NON-DOM INTERNAL: Pre-mutation context check, in
* preparation for later generating DOMAttrModified events.
* Determines whether this node is within an Attr
* @param node node to get enclosing attribute for
* @return either a description of that Attr, or null if none such.
*/
protected void saveEnclosingAttr(NodeImpl node) {
savedEnclosingAttr = null;
// MUTATION PREPROCESSING AND PRE-EVENTS:
// If we're within the scope of an Attr and DOMAttrModified
// was requested, we need to preserve its previous value for
// that event.
LCount lc = LCount.lookup(MutationEventImpl.DOM_ATTR_MODIFIED);
if (lc.total > 0) {
NodeImpl eventAncestor = node;
while (true) {
if (eventAncestor == null)
return;
int type = eventAncestor.getNodeType();
if (type == Node.ATTRIBUTE_NODE) {
EnclosingAttr retval = new EnclosingAttr();
retval.node = (AttrImpl) eventAncestor;
retval.oldvalue = retval.node.getNodeValue();
savedEnclosingAttr = retval;
return;
}
else if (type == Node.ENTITY_REFERENCE_NODE)
eventAncestor = eventAncestor.parentNode();
else if (type == Node.TEXT_NODE)
eventAncestor = eventAncestor.parentNode();
else
return;
// Any other parent means we're not in an Attr
}
}
}
示例10: parseDescriptionNode
/**
* Process a rule descrtiprion node
* @param rule the rule being constructed
* @param descriptionNode must be a description element node
*/
private void parseDescriptionNode(Rule rule, Node descriptionNode) {
NodeList nodeList = descriptionNode.getChildNodes();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.CDATA_SECTION_NODE) {
buffer.append(node.getNodeValue());
} else if (node.getNodeType() == Node.TEXT_NODE) {
buffer.append(node.getNodeValue());
}
}
rule.setDescription(buffer.toString());
}
示例11: getWholeTextForward
/**
* Concatenates the text of all logically-adjacent text nodes to the
* right of this node
* @param node
* @param buffer
* @param parent
* @return true - if execution was stopped because the type of node
* other than EntityRef, Text, CDATA is encountered, otherwise
* return false
*/
private boolean getWholeTextForward(Node node, StringBuffer buffer, Node parent){
// boolean to indicate whether node is a child of an entity reference
boolean inEntRef = false;
if (parent!=null) {
inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
}
while (node != null) {
short type = node.getNodeType();
if (type == Node.ENTITY_REFERENCE_NODE) {
if (getWholeTextForward(node.getFirstChild(), buffer, node)){
return true;
}
}
else if (type == Node.TEXT_NODE ||
type == Node.CDATA_SECTION_NODE) {
((NodeImpl)node).getTextContent(buffer);
}
else {
return true;
}
node = node.getNextSibling();
}
// if the parent node is an entity reference node, must
// check nodes to the right of the parent entity reference node for logically adjacent
// text nodes
if (inEntRef) {
getWholeTextForward(parent.getNextSibling(), buffer, parent.getParentNode());
return true;
}
return false;
}
示例12: print
public void print(Node node) throws XMLStreamException {
switch (node.getNodeType()) {
case Node.DOCUMENT_NODE:
visitDocument((Document) node);
break;
case Node.DOCUMENT_FRAGMENT_NODE:
visitDocumentFragment((DocumentFragment) node);
break;
case Node.ELEMENT_NODE:
visitElement((Element) node);
break;
case Node.TEXT_NODE:
visitText((Text) node);
break;
case Node.CDATA_SECTION_NODE:
visitCDATASection((CDATASection) node);
break;
case Node.PROCESSING_INSTRUCTION_NODE:
visitProcessingInstruction((ProcessingInstruction) node);
break;
case Node.ENTITY_REFERENCE_NODE:
visitReference((EntityReference) node);
break;
case Node.COMMENT_NODE:
visitComment((Comment) node);
break;
case Node.DOCUMENT_TYPE_NODE:
break;
case Node.ATTRIBUTE_NODE:
case Node.ENTITY_NODE:
default:
throw new XMLStreamException("Unexpected DOM Node Type "
+ node.getNodeType()
);
}
}
示例13: findText
/**
* Helper method that searches for first text node, between all children of current node
* and returns its value. (This is needed to garbage out all comments)
* @param elem root node to begin search
* @return parsed text if found, otherwise null
*/
protected static String findText(Node elem) {
NodeList tmp = elem.getChildNodes();
for (int j = 0; j < tmp.getLength(); j++) {
if (tmp.item(j).getNodeType() == Node.TEXT_NODE) {
return tmp.item(j).getNodeValue();
}
}
return null;
}
示例14: addNodeInTree2
private static void addNodeInTree2(Node node, Document document, Element parent, int [] index) {
Element currentElement = createElement2(document, node, index);
currentElement.setAttribute("type", Short.toString(node.getNodeType()));
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
currentElement.setAttribute("text", node.getNodeName());
NamedNodeMap map = node.getAttributes();
if (node.hasAttributes()) {
Element attributes = createElement2(document, node, index);
attributes.setAttribute("text", "Attributes");
attributes.setAttribute("type", Short.toString(Node.ATTRIBUTE_NODE));
currentElement.appendChild(attributes);
for (int i = 0; i < map.getLength(); ++i) {
Element attribute = createElement2(document, map.item(i), index);
attribute.setAttribute("text", map.item(i).getNodeName() + "=\"" + map.item(i).getNodeValue() + "\"");
attribute.setAttribute("type", Short.toString(Node.ATTRIBUTE_NODE));
attributes.appendChild(attribute);
}
}
break;
case Node.TEXT_NODE:
currentElement.setAttribute("text", node.getNodeValue() == null ? "" : node.getNodeValue().trim());
break;
case Node.ENTITY_NODE:
currentElement.setAttribute("text", "[Entity]");
break;
case Node.ENTITY_REFERENCE_NODE:
currentElement.setAttribute("text", "[Entityref]");
break;
case Node.PROCESSING_INSTRUCTION_NODE:
currentElement.setAttribute("text", "[Pi]");
break;
case Node.COMMENT_NODE:
currentElement.setAttribute("text", "[Comment]");
break;
case Node.DOCUMENT_FRAGMENT_NODE:
currentElement.setAttribute("text", "[Docfgmt]");
break;
case Node.DOCUMENT_TYPE_NODE:
currentElement.setAttribute("text", "[Doctype]");
break;
case Node.NOTATION_NODE:
currentElement.setAttribute("text", "[Notation]");
break;
default:
break;
}
parent.appendChild(currentElement);
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node currentNode = nodeList.item(i);
addNodeInTree2(currentNode, document, currentElement, index);
}
}
示例15: duplicateNode
/**
* Helper method used by {@link #findAlternateToolsXml(InputStream)} to duplicate a node
* and attach it to the given root in the new document.
*/
private Element duplicateNode(Element newRootNode, Element oldNode,
String namespaceUri, String prefix) {
// The implementation here is more or less equivalent to
//
// newRoot.appendChild(newDoc.importNode(oldNode, deep=true))
//
// except we can't just use importNode() since we need to deal with the fact
// that the old document is not namespace-aware yet the new one is.
Document newDoc = newRootNode.getOwnerDocument();
Element newNode = null;
String nodeName = oldNode.getNodeName();
int pos = nodeName.indexOf(':');
if (pos > 0 && pos < nodeName.length() - 1) {
nodeName = nodeName.substring(pos + 1);
newNode = newDoc.createElementNS(namespaceUri, nodeName);
newNode.setPrefix(prefix);
} else {
newNode = newDoc.createElement(nodeName);
}
newRootNode.appendChild(newNode);
// Merge in all the attributes
NamedNodeMap attrs = oldNode.getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
Attr attr = (Attr) attrs.item(i);
Attr newAttr = null;
String attrName = attr.getNodeName();
pos = attrName.indexOf(':');
if (pos > 0 && pos < attrName.length() - 1) {
attrName = attrName.substring(pos + 1);
newAttr = newDoc.createAttributeNS(namespaceUri, attrName);
newAttr.setPrefix(prefix);
} else {
newAttr = newDoc.createAttribute(attrName);
}
newAttr.setNodeValue(attr.getNodeValue());
if (pos > 0) {
newNode.getAttributes().setNamedItemNS(newAttr);
} else {
newNode.getAttributes().setNamedItem(newAttr);
}
}
// Merge all child elements and texts
for (Node child = oldNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
duplicateNode(newNode, (Element) child, namespaceUri, prefix);
} else if (child.getNodeType() == Node.TEXT_NODE) {
Text newText = newDoc.createTextNode(child.getNodeValue());
newNode.appendChild(newText);
}
}
return newNode;
}