本文整理了Java中org.w3c.dom.Node.getNodeType()
方法的一些代码示例,展示了Node.getNodeType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getNodeType()
方法的具体详情如下:
包路径:org.w3c.dom.Node
类名称:Node
方法名:getNodeType
[英]A code representing the type of the underlying object, as defined above.
[中]表示基础对象类型的代码,如上所述。
代码示例来源:origin: skylot/jadx
private void parse(Document doc) {
NodeList nodeList = doc.getChildNodes();
for (int count = 0; count < nodeList.getLength(); count++) {
Node node = nodeList.item(count);
if (node.getNodeType() == Node.ELEMENT_NODE
&& node.hasChildNodes()) {
parseAttrList(node.getChildNodes());
}
}
}
代码示例来源:origin: pmd/pmd
private static boolean isElementNode(Node node, String name) {
return node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name);
}
代码示例来源:origin: libgdx/libgdx
private void addToDependencyMapFromXML (Map<String, List<ExternalExtensionDependency>> dependencies, Element eElement, String platform) {
if (eElement.getElementsByTagName(platform).item(0) != null) {
Element project = (Element)eElement.getElementsByTagName(platform).item(0);
ArrayList<ExternalExtensionDependency> deps = new ArrayList<ExternalExtensionDependency>();
if (project.getTextContent().trim().equals("")) {
// No dependencies required
} else if (project.getTextContent().trim().equals("null")) {
// Not supported
deps = null;
} else {
NodeList nList = project.getElementsByTagName("dependency");
for (int i = 0; i < nList.getLength(); i++) {
Node nNode = nList.item(i);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element dependencyNode = (Element)nNode;
boolean external = Boolean.parseBoolean(dependencyNode.getAttribute("external"));
deps.add(new ExternalExtensionDependency(dependencyNode.getTextContent(), external));
}
}
}
dependencies.put(platform, deps);
}
}
代码示例来源:origin: Tencent/tinker
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
String resourceType = node.getNodeName();
if (resourceType.equals(ITEM_TAG)) {
resourceType = node.getAttributes().getNamedItem("type").getNodeValue();
if (resourceType.equals("id")) {
resourceCollector.addIgnoreId(node.getAttributes().getNamedItem("name").getNodeValue());
代码示例来源:origin: groovy/groovy-core
public static String text(Node node) {
if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
return node.getNodeValue();
}
if (node.hasChildNodes()) {
return text(node.getChildNodes());
}
return "";
}
代码示例来源:origin: oracle/opengrok
private String getValue(Node node) {
if (node == null) {
return null;
}
StringBuilder sb = new StringBuilder();
Node n = node.getFirstChild();
while (n != null) {
if (n.getNodeType() == Node.TEXT_NODE) {
sb.append(n.getNodeValue());
}
n = n.getNextSibling();
}
return sb.toString();
}
代码示例来源:origin: Tencent/tinker
private void readPackageConfigFromXml(Node node) throws IOException {
NodeList childNodes = node.getChildNodes();
if (childNodes.getLength() > 0) {
for (int j = 0, n = childNodes.getLength(); j < n; j++) {
Node child = childNodes.item(j);
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element check = (Element) child;
String tagName = check.getTagName();
String value = check.getAttribute(ATTR_VALUE);
String name = check.getAttribute(ATTR_NAME);
if (tagName.equals(ATTR_CONFIG_FIELD)) {
mPackageFields.put(name, value);
} else {
System.err.println("unknown package config tag " + tagName);
}
}
}
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Reconstructs the resource from the XML file
*/
@SuppressWarnings("unchecked")
public SsurgeonWordlist(Element rootElt) {
id = rootElt.getAttribute("id");
NodeList wordEltNL = rootElt.getElementsByTagName(WORD_ELT);
for (int i=0; i<wordEltNL.getLength(); i++) {
Node node = wordEltNL.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
String word = Ssurgeon.getEltText((Element) node);
words.add(word);
}
}
}
代码示例来源:origin: xalan/xalan
/**
* Given a node, determine if it is a namespace node.
*
* @param node
*
* @return boolean Returns true if this is a namespace node; otherwise, returns false.
*/
private boolean isNamespaceNode(Node node) {
if ((null != node) &&
(node.getNodeType() == Node.ATTRIBUTE_NODE) &&
(node.getNodeName().startsWith("xmlns:") || node.getNodeName().equals("xmlns"))) {
return true;
} else {
return false;
}
}
代码示例来源:origin: com.sun.xml.bind/jaxb-impl
private void visit( Node n ) throws SAXException {
setCurrentLocation( n );
// if a case statement gets too big, it should be made into a separate method.
switch(n.getNodeType()) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
String value = n.getNodeValue();
receiver.characters( value.toCharArray(), 0, value.length() );
break;
case Node.ELEMENT_NODE:
visit( (Element)n );
break;
case Node.ENTITY_REFERENCE_NODE:
receiver.skippedEntity(n.getNodeName());
break;
case Node.PROCESSING_INSTRUCTION_NODE:
ProcessingInstruction pi = (ProcessingInstruction)n;
receiver.processingInstruction(pi.getTarget(),pi.getData());
break;
}
}
代码示例来源:origin: androidquery/androidquery
private String text(Node n){
String text = null;
switch(n.getNodeType()){
case Node.TEXT_NODE:
text = n.getNodeValue();
if(text != null) text = text.trim();
break;
case Node.CDATA_SECTION_NODE:
text = n.getNodeValue();
break;
default:
//AQUtility.debug("unknown", n);
}
if(text == null) text = "";
return text;
}
代码示例来源:origin: pmd/pmd
private static String parseTextNode(Node exampleNode) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < exampleNode.getChildNodes().getLength(); i++) {
Node node = exampleNode.getChildNodes().item(i);
if (node.getNodeType() == Node.CDATA_SECTION_NODE || node.getNodeType() == Node.TEXT_NODE) {
buffer.append(node.getNodeValue());
}
}
return buffer.toString().trim();
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* For the given element, finds the first child Element with the given tag.
*/
private static Element getFirstTag(Element element, String tag) {
try {
NodeList nodeList = element.getElementsByTagName(tag);
if (nodeList.getLength() == 0) return null;
for (int i=0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
return (Element) node;
}
} catch (Exception e) {
log.warning("Error getting first tag "+tag+" under element="+element);
}
return null;
}
代码示例来源:origin: org.freemarker/freemarker
void outputContent(NamedNodeMap nodes, StringBuilder buf) {
for (int i = 0; i < nodes.getLength(); ++i) {
Node n = nodes.item(i);
if (n.getNodeType() != Node.ATTRIBUTE_NODE
|| (!n.getNodeName().startsWith("xmlns:") && !n.getNodeName().equals("xmlns"))) {
outputContent(n, buf);
}
}
}
代码示例来源:origin: groovy/groovy-core
public static String toString(Object o) {
if (o instanceof Node) {
if (((Node) o).getNodeType() == Node.TEXT_NODE) {
return ((Node) o).getNodeValue();
}
}
if (o instanceof NodeList) {
return toString((NodeList) o);
}
return o.toString();
}
代码示例来源:origin: hibernate/hibernate-orm
private static String extractContent(Element element, String defaultStr) {
if ( element == null ) {
return defaultStr;
}
NodeList children = element.getChildNodes();
StringBuilder result = new StringBuilder("");
for ( int i = 0; i < children.getLength() ; i++ ) {
if ( children.item( i ).getNodeType() == Node.TEXT_NODE ||
children.item( i ).getNodeType() == Node.CDATA_SECTION_NODE ) {
result.append( children.item( i ).getNodeValue() );
}
}
return result.toString().trim();
}
代码示例来源:origin: libgdx/libgdx
private void writeUpdatedTMX (TiledMap tiledMap, FileHandle tmxFileHandle) throws IOException {
Document doc;
DocumentBuilder docBuilder;
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
try {
docBuilder = docFactory.newDocumentBuilder();
doc = docBuilder.parse(tmxFileHandle.read());
Node map = doc.getFirstChild();
while (map.getNodeType() != Node.ELEMENT_NODE || map.getNodeName() != "map") {
if ((map = map.getNextSibling()) == null) {
throw new GdxRuntimeException("Couldn't find map node!");
}
}
setProperty(doc, map, "atlas", settings.tilesetOutputDirectory + "/" + settings.atlasOutputName + ".atlas");
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
outputDir.mkdirs();
StreamResult result = new StreamResult(new File(outputDir, tmxFileHandle.name()));
transformer.transform(source, result);
} catch (ParserConfigurationException e) {
throw new RuntimeException("ParserConfigurationException: " + e.getMessage());
} catch (SAXException e) {
throw new RuntimeException("SAXException: " + e.getMessage());
} catch (TransformerConfigurationException e) {
throw new RuntimeException("TransformerConfigurationException: " + e.getMessage());
} catch (TransformerException e) {
throw new RuntimeException("TransformerException: " + e.getMessage());
}
}
代码示例来源:origin: Tencent/tinker
private void readLibPatternsFromXml(Node node) throws IOException {
NodeList childNodes = node.getChildNodes();
if (childNodes.getLength() > 0) {
for (int j = 0, n = childNodes.getLength(); j < n; j++) {
Node child = childNodes.item(j);
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element check = (Element) child;
String tagName = check.getTagName();
String value = check.getAttribute(ATTR_VALUE);
if (tagName.equals(ATTR_PATTERN)) {
addToPatterns(value, mSoFilePattern);
} else {
System.err.println("unknown dex tag " + tagName);
}
}
}
}
}
代码示例来源:origin: libgdx/libgdx
private void writeUpdatedTMX (TiledMap tiledMap, FileHandle tmxFileHandle) throws IOException {
Document doc;
DocumentBuilder docBuilder;
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
try {
docBuilder = docFactory.newDocumentBuilder();
doc = docBuilder.parse(tmxFileHandle.read());
Node map = doc.getFirstChild();
while (map.getNodeType() != Node.ELEMENT_NODE || map.getNodeName() != "map") {
if ((map = map.getNextSibling()) == null) {
throw new GdxRuntimeException("Couldn't find map node!");
}
}
setProperty(doc, map, "atlas", settings.tilesetOutputDirectory + "/" + settings.atlasOutputName + ".atlas");
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
outputDir.mkdirs();
StreamResult result = new StreamResult(new File(outputDir, tmxFileHandle.name()));
transformer.transform(source, result);
} catch (ParserConfigurationException e) {
throw new RuntimeException("ParserConfigurationException: " + e.getMessage());
} catch (SAXException e) {
throw new RuntimeException("SAXException: " + e.getMessage());
} catch (TransformerConfigurationException e) {
throw new RuntimeException("TransformerConfigurationException: " + e.getMessage());
} catch (TransformerException e) {
throw new RuntimeException("TransformerException: " + e.getMessage());
}
}
代码示例来源:origin: spring-projects/spring-framework
public BeanDefinitionHolder decorateBeanDefinitionIfRequired(
Element ele, BeanDefinitionHolder definitionHolder, @Nullable BeanDefinition containingBd) {
BeanDefinitionHolder finalDefinition = definitionHolder;
// Decorate based on custom attributes first.
NamedNodeMap attributes = ele.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Node node = attributes.item(i);
finalDefinition = decorateIfRequired(node, finalDefinition, containingBd);
}
// Decorate based on custom nested elements.
NodeList children = ele.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
finalDefinition = decorateIfRequired(node, finalDefinition, containingBd);
}
}
return finalDefinition;
}
内容来源于网络,如有侵权,请联系作者删除!