本文整理了Java中org.w3c.dom.Node.getNodeName()
方法的一些代码示例,展示了Node.getNodeName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getNodeName()
方法的具体详情如下:
包路径:org.w3c.dom.Node
类名称:Node
方法名:getNodeName
[英]The name of this node, depending on its type; see the table above.
[中]此节点的名称,取决于其类型;见上表。
代码示例来源:origin: libgdx/libgdx
/** If the child node doesn't exist, it is created. */
private static Node getFirstChildNodeByName (Node parent, String child) {
NodeList childNodes = parent.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
if (childNodes.item(i).getNodeName().equals(child)) {
return childNodes.item(i);
}
}
Node newNode = parent.getOwnerDocument().createElement(child);
if (childNodes.item(0) != null)
return parent.insertBefore(newNode, childNodes.item(0));
else
return parent.appendChild(newNode);
}
代码示例来源:origin: robolectric/robolectric
private static HashMap<String, String> parseNodeAttributes(Node node) {
final NamedNodeMap attributes = node.getAttributes();
final int attrCount = attributes.getLength();
final HashMap<String, String> receiverAttrs = new HashMap<>(attributes.getLength());
for (int i = 0; i < attrCount; i++) {
Node attribute = attributes.item(i);
String value = attribute.getNodeValue();
if (value != null) {
receiverAttrs.put(attribute.getNodeName(), value);
}
}
return receiverAttrs;
}
代码示例来源:origin: pmd/pmd
private static boolean isElementNode(Node node, String name) {
return node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name);
}
代码示例来源:origin: apache/incubator-dubbo
private static void parseProperties(NodeList nodeList, RootBeanDefinition beanDefinition) {
if (nodeList != null && nodeList.getLength() > 0) {
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
if ("property".equals(node.getNodeName())
|| "property".equals(node.getLocalName())) {
String name = ((Element) node).getAttribute("name");
if (name != null && name.length() > 0) {
String value = ((Element) node).getAttribute("value");
String ref = ((Element) node).getAttribute("ref");
if (value != null && value.length() > 0) {
beanDefinition.getPropertyValues().addPropertyValue(name, value);
} else if (ref != null && ref.length() > 0) {
beanDefinition.getPropertyValues().addPropertyValue(name, new RuntimeBeanReference(ref));
} else {
throw new UnsupportedOperationException("Unsupported <property name=\"" + name + "\"> sub tag, Only supported <property name=\"" + name + "\" ref=\"...\" /> or <property name=\"" + name + "\" value=\"...\" />");
}
}
}
}
}
}
}
代码示例来源: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: pmd/pmd
@Override
public Attribute next() {
org.w3c.dom.Node attributeNode = attributes.item(index++);
return new Attribute(XmlNodeWrapper.this,
attributeNode.getNodeName(),
attributeNode.getNodeValue());
}
代码示例来源:origin: checkstyle/checkstyle
private static void verifyXmlNode(Node expected, Node actual, String path,
BiPredicate<Node, Node> ordered) {
if (expected == null) {
if (actual != null) {
Assert.fail("no node should exist: " + path + actual.getNodeName() + "/");
}
}
else {
final String newPath = path + expected.getNodeName() + "/";
Assert.assertNotNull("node should exist: " + newPath, actual);
Assert.assertEquals("node should have same name: " + newPath, expected.getNodeName(),
actual.getNodeName());
Assert.assertEquals("node should have same type: " + newPath, expected.getNodeType(),
actual.getNodeType());
verifyXmlAttributes(expected.getAttributes(), actual.getAttributes(), newPath);
verifyXmlNodes(expected, actual, newPath, ordered);
}
}
代码示例来源:origin: libgdx/libgdx
/** If the child node doesn't exist, it is created. */
private static Node getFirstChildNodeByName (Node parent, String child) {
NodeList childNodes = parent.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
if (childNodes.item(i).getNodeName().equals(child)) {
return childNodes.item(i);
}
}
Node newNode = parent.getOwnerDocument().createElement(child);
if (childNodes.item(0) != null)
return parent.insertBefore(newNode, childNodes.item(0));
else
return parent.appendChild(newNode);
}
代码示例来源:origin: apache/incubator-dubbo
private static void parseProperties(NodeList nodeList, RootBeanDefinition beanDefinition) {
if (nodeList != null && nodeList.getLength() > 0) {
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
if ("property".equals(node.getNodeName())
|| "property".equals(node.getLocalName())) {
String name = ((Element) node).getAttribute("name");
if (name != null && name.length() > 0) {
String value = ((Element) node).getAttribute("value");
String ref = ((Element) node).getAttribute("ref");
if (value != null && value.length() > 0) {
beanDefinition.getPropertyValues().addPropertyValue(name, value);
} else if (ref != null && ref.length() > 0) {
beanDefinition.getPropertyValues().addPropertyValue(name, new RuntimeBeanReference(ref));
} else {
throw new UnsupportedOperationException("Unsupported <property name=\"" + name + "\"> sub tag, Only supported <property name=\"" + name + "\" ref=\"...\" /> or <property name=\"" + name + "\" value=\"...\" />");
}
}
}
}
}
}
}
代码示例来源:origin: Tencent/tinker
private static String nodeToString(Node node, boolean isNoChild) {
StringBuilder stringBuilder = new StringBuilder();
if (node != null) {
stringBuilder.append(node.getNodeName());
NamedNodeMap namedNodeMap = node.getAttributes();
stringBuilder.append(Constant.Symbol.MIDDLE_BRACKET_LEFT);
int namedNodeMapLength = namedNodeMap.getLength();
for (int j = 0; j < namedNodeMapLength; j++) {
Node attributeNode = namedNodeMap.item(j);
stringBuilder.append(Constant.Symbol.AT + attributeNode.getNodeName() + Constant.Symbol.EQUAL + attributeNode.getNodeValue());
if (j < namedNodeMapLength - 1) {
stringBuilder.append(Constant.Symbol.COMMA);
}
}
stringBuilder.append(Constant.Symbol.MIDDLE_BRACKET_RIGHT);
String value = StringUtil.nullToBlank(isNoChild ? node.getTextContent() : node.getNodeValue()).trim();
if (StringUtil.isNotBlank(value)) {
stringBuilder.append(Constant.Symbol.EQUAL + value);
}
}
return stringBuilder.toString();
}
代码示例来源: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: nutzam/nutz
/**
* 获取该 XML 元素内所有的属性的值,按照Map的形式返回
*
* @param ele
* XML 元素
* @return 所有属性的值
*/
public static Map<String, String> getAttrs(Element ele) {
NamedNodeMap nodeMap = ele.getAttributes();
Map<String, String> attrs = new HashMap<String, String>(nodeMap.getLength());
for (int i = 0; i < nodeMap.getLength(); i++) {
attrs.put(nodeMap.item(i).getNodeName(), nodeMap.item(i).getNodeValue());
}
return attrs;
}
代码示例来源:origin: robolectric/robolectric
private List<Node> getChildrenTags(final Node node, final String tagName) {
List<Node> children = new ArrayList<>();
for (int i = 0; i < node.getChildNodes().getLength(); i++) {
Node childNode = node.getChildNodes().item(i);
if (childNode.getNodeName().equalsIgnoreCase(tagName)) {
children.add(childNode);
}
}
return children;
}
代码示例来源:origin: apache/incubator-dubbo
private static void parseNested(Element element, ParserContext parserContext, Class<?> beanClass, boolean required, String tag, String property, String ref, BeanDefinition beanDefinition) {
NodeList nodeList = element.getChildNodes();
if (nodeList != null && nodeList.getLength() > 0) {
boolean first = true;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
if (tag.equals(node.getNodeName())
|| tag.equals(node.getLocalName())) {
if (first) {
first = false;
String isDefault = element.getAttribute("default");
if (StringUtils.isEmpty(isDefault)) {
beanDefinition.getPropertyValues().addPropertyValue("default", "false");
}
}
BeanDefinition subDefinition = parse((Element) node, parserContext, beanClass, required);
if (subDefinition != null && ref != null && ref.length() > 0) {
subDefinition.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(ref));
}
}
}
}
}
}
代码示例来源:origin: real-logic/simple-binary-encoding
/**
* Helper function that throws an exception when the attribute is not set.
*
* @param elementNode that should have the attribute
* @param attrName that is to be looked up
* @return value of the attribute
* @throws IllegalArgumentException if the attribute is not present
*/
public static String getAttributeValue(final Node elementNode, final String attrName)
{
final Node attrNode = elementNode.getAttributes().getNamedItemNS(null, attrName);
if (attrNode == null || "".equals(attrNode.getNodeValue()))
{
throw new IllegalStateException(
"Element '" + elementNode.getNodeName() + "' has empty or missing attribute: " + attrName);
}
return attrNode.getNodeValue();
}
代码示例来源: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: apache/geode
static String findPrefix(final Element root, final String namespaceUri) {
// Look for all of the attributes of cache that start with xmlns
NamedNodeMap attributes = root.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Node item = attributes.item(i);
if (item.getNodeName().startsWith("xmlns")) {
if (item.getNodeValue().equals(namespaceUri)) {
String[] splitName = item.getNodeName().split(":");
if (splitName.length > 1) {
return splitName[1];
} else {
return "";
}
}
}
}
return null;
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Searches for all immediate children with the given name
*/
protected static List<Node> getChildrenByName(Node node, String name) {
List<Node> matches = new ArrayList<>();
NodeList children = node.getChildNodes();
// search children
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeName().equals(name)) {
matches.add(child);
}
}
return matches;
}
代码示例来源:origin: apache/incubator-dubbo
private static void parseNested(Element element, ParserContext parserContext, Class<?> beanClass, boolean required, String tag, String property, String ref, BeanDefinition beanDefinition) {
NodeList nodeList = element.getChildNodes();
if (nodeList != null && nodeList.getLength() > 0) {
boolean first = true;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
if (tag.equals(node.getNodeName())
|| tag.equals(node.getLocalName())) {
if (first) {
first = false;
String isDefault = element.getAttribute("default");
if (StringUtils.isEmpty(isDefault)) {
beanDefinition.getPropertyValues().addPropertyValue("default", "false");
}
}
BeanDefinition subDefinition = parse((Element) node, parserContext, beanClass, required);
if (subDefinition != null && ref != null && ref.length() > 0) {
subDefinition.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(ref));
}
}
}
}
}
}
代码示例来源:origin: typ0520/fastdex
private static String nodeToString(Node node, boolean isNoChild) {
StringBuilder stringBuilder = new StringBuilder();
if (node != null) {
stringBuilder.append(node.getNodeName());
NamedNodeMap namedNodeMap = node.getAttributes();
stringBuilder.append(Constant.Symbol.MIDDLE_BRACKET_LEFT);
int namedNodeMapLength = namedNodeMap.getLength();
for (int j = 0; j < namedNodeMapLength; j++) {
Node attributeNode = namedNodeMap.item(j);
stringBuilder.append(Constant.Symbol.AT + attributeNode.getNodeName() + Constant.Symbol.EQUAL + attributeNode.getNodeValue());
if (j < namedNodeMapLength - 1) {
stringBuilder.append(Constant.Symbol.COMMA);
}
}
stringBuilder.append(Constant.Symbol.MIDDLE_BRACKET_RIGHT);
String value = StringUtil.nullToBlank(isNoChild ? node.getTextContent() : node.getNodeValue()).trim();
if (StringUtil.isNotBlank(value)) {
stringBuilder.append(Constant.Symbol.EQUAL + value);
}
}
return stringBuilder.toString();
}
内容来源于网络,如有侵权,请联系作者删除!