本文整理了Java中org.w3c.dom.Node.getAttributes()
方法的一些代码示例,展示了Node.getAttributes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getAttributes()
方法的具体详情如下:
包路径:org.w3c.dom.Node
类名称:Node
方法名:getAttributes
[英]A NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise.
[中]包含此节点属性的NamedNodeMap
(如果是Element
)或null
否则。
代码示例来源:origin: androidannotations/androidannotations
private List<String> extractUsesPermissionNames(NodeList usesPermissionNodes) {
List<String> usesPermissionQualifiedNames = new ArrayList<>();
for (int i = 0; i < usesPermissionNodes.getLength(); i++) {
Node usesPermissionNode = usesPermissionNodes.item(i);
Node nameAttribute = usesPermissionNode.getAttributes().getNamedItem("android:name");
if (nameAttribute == null) {
return null;
}
usesPermissionQualifiedNames.add(nameAttribute.getNodeValue());
}
return usesPermissionQualifiedNames;
}
代码示例来源:origin: Tencent/tinker
private static String extractNameAttribute(Node node) {
return node.getAttributes().getNamedItem("name").getNodeValue();
}
代码示例来源:origin: stanfordnlp/CoreNLP
public static Node getAttribute(Node node, String name) {
return node.getAttributes().getNamedItem(name);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public int compare(Node o1, Node o2) {
NamedNodeMap attributes1 = o1.getAttributes();
NamedNodeMap attributes2 = o2.getAttributes();
if (attributes1 == null) {
return 1;
} else if (attributes2 == null) {
return -1;
} else if (MO_TAB.equals(o1.getNodeName()) && !MO_TAB.equals(o2.getNodeName())) {
return -1;
} else if (!MO_TAB.equals(o1.getNodeName()) && MO_TAB.equals(o2.getNodeName())) {
return 1;
} else if (MO_GROUP.equals(o1.getNodeName()) && !MO_GROUP.equals(o2.getNodeName())) {
if (MO_TAB.equals(o1.getNodeName()) && MO_TAB.equals(o2.getNodeName())) {
id1 = attributes1.getNamedItem(TAB_NAME);
id2 = attributes2.getNamedItem(TAB_NAME);
} else if (MO_GROUP.equals(o1.getNodeName()) && MO_GROUP.equals(o2.getNodeName())) {
id1 = attributes1.getNamedItem(GROUP_NAME);
id2 = attributes2.getNamedItem(GROUP_NAME);
} else {
return -1;
String idVal1 = id1.getNodeValue();
String idVal2 = id2.getNodeValue();
return idVal1.compareTo(idVal2);
代码示例来源:origin: log4j/log4j
protected void processLogLevels(Document doc) {
NodeList nodeList = doc.getElementsByTagName(LEVEL);
Map menuItems = _monitor.getLogLevelMenuItems();
for (int i = 0; i < nodeList.getLength(); i++) {
Node n = nodeList.item(i);
NamedNodeMap map = n.getAttributes();
String name = getValue(map, NAME);
try {
JCheckBoxMenuItem item =
(JCheckBoxMenuItem) menuItems.get(LogLevel.valueOf(name));
item.setSelected(getValue(map, SELECTED).equalsIgnoreCase("true"));
} catch (LogLevelFormatException e) {
// ignore it will be on by default.
}
}
}
代码示例来源: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: iBotPeaches/Apktool
/**
* Removes "debug" tag from file
*
* @param file AndroidManifest file
* @throws AndrolibException
*/
public static void removeApplicationDebugTag(File file) throws AndrolibException {
if (file.exists()) {
try {
Document doc = loadDocument(file);
Node application = doc.getElementsByTagName("application").item(0);
// load attr
NamedNodeMap attr = application.getAttributes();
Node debugAttr = attr.getNamedItem("android:debuggable");
// remove application:debuggable
if (debugAttr != null) {
attr.removeNamedItem("android:debuggable");
}
saveDocument(file, doc);
} catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
}
}
}
代码示例来源: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: log4j/log4j
protected void processRecordFilter(Document doc) {
NodeList nodeList = doc.getElementsByTagName(NDCTEXTFILTER);
// there is only one value stored
Node n = nodeList.item(0);
// add check for backwards compatibility as this feature was added in
// version 1.2
if (n == null) {
return;
}
NamedNodeMap map = n.getAttributes();
String text = getValue(map, NAME);
if (text == null || text.equals("")) {
return;
}
_monitor.setNDCLogRecordFilter(text);
}
代码示例来源:origin: pentaho/pentaho-kettle
/**
* Get all the attributes in a certain node (on the root level)
*
* @param node
* The node to examine
* @return an array of strings containing the names of the attributes.
*/
public static String[] getNodeAttributes( Node node ) {
NamedNodeMap nnm = node.getAttributes();
if ( nnm != null ) {
String[] attributes = new String[nnm.getLength()];
for ( int i = 0; i < nnm.getLength(); i++ ) {
Node attr = nnm.item( i );
attributes[i] = attr.getNodeName();
}
return attributes;
}
return null;
}
代码示例来源:origin: org.testng/testng
private void populateAttributes(Node node, Object object) throws XPathExpressionException {
for (int j = 0; j < node.getAttributes().getLength(); j++) {
Node item = node.getAttributes().item(j);
setProperty(object, item.getLocalName(), item.getNodeValue());
}
}
代码示例来源:origin: robolectric/robolectric
private void parseUsedPermissions(Document manifestDocument) {
NodeList elementsByTagName = manifestDocument.getElementsByTagName("uses-permission");
int length = elementsByTagName.getLength();
for (int i = 0; i < length; i++) {
Node node = elementsByTagName.item(i).getAttributes().getNamedItem("android:name");
usedPermissions.add(node.getNodeValue());
}
}
代码示例来源:origin: Tencent/tinker
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: log4j/log4j
protected void processCategories(Document doc) {
CategoryExplorerTree tree = _monitor.getCategoryExplorerTree();
CategoryExplorerModel model = tree.getExplorerModel();
NodeList nodeList = doc.getElementsByTagName(CATEGORY);
// determine where the starting node is
NamedNodeMap map = nodeList.item(0).getAttributes();
int j = (getValue(map, NAME).equalsIgnoreCase(FIRST_CATEGORY_NAME)) ? 1 : 0;
// iterate backwards throught the nodeList so that expansion of the
// list can occur
for (int i = nodeList.getLength() - 1; i >= j; i--) {
Node n = nodeList.item(i);
map = n.getAttributes();
CategoryNode chnode = model.addCategory(new CategoryPath(getValue(map, PATH)));
chnode.setSelected((getValue(map, SELECTED).equalsIgnoreCase("true")) ? true : false);
if (getValue(map, EXPANDED).equalsIgnoreCase("true")) ;
tree.expandPath(model.getTreePathToRoot(chnode));
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Fetches the value of a given attribute
*/
public static String getAttributeValue(Node node, String attributeName) {
try {
return node.getAttributes().getNamedItem(attributeName).getNodeValue();
} catch (Exception e) {
}
return null;
}
代码示例来源: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: apache/geode
/**
* Replaces the node's attributes with the attributes in the given hashmap
*
* @param node XML node that should be edited
* @param attributes HashMap of strings representing the attributes of a node (key = value)
* @return The given node with ONLY the given attributes
*/
private static Node rewriteNodeAttributes(Node node, HashMap<String, String> attributes) {
NamedNodeMap nodeAttrs = node.getAttributes();
// Remove all previous attributes
while (nodeAttrs.getLength() > 0) {
nodeAttrs.removeNamedItem(nodeAttrs.item(0).getNodeName());
}
// Set to new attributes
for (String key : attributes.keySet()) {
((Element) node).setAttribute(key, attributes.get(key));
}
return node;
}
代码示例来源:origin: robolectric/robolectric
private @Nullable String getAttributeValue(Node parentNode, String attributeName) {
Node attributeNode = parentNode.getAttributes().getNamedItem(attributeName);
return attributeNode == null ? null : attributeNode.getTextContent();
}
代码示例来源:origin: org.testng/testng
private void populateAttributes(Node node, Object object) {
for (int j = 0; j < node.getAttributes().getLength(); j++) {
Node item = node.getAttributes().item(j);
p(node.getAttributes().item(j).toString());
setProperty(object, item.getLocalName(), item.getNodeValue());
}
}
代码示例来源:origin: robolectric/robolectric
private static String getTagAttributeText(final Document doc, final String tag, final String attribute) {
NodeList elementsByTagName = doc.getElementsByTagName(tag);
for (int i = 0; i < elementsByTagName.getLength(); ++i) {
Node item = elementsByTagName.item(i);
Node namedItem = item.getAttributes().getNamedItem(attribute);
if (namedItem != null) {
return namedItem.getTextContent();
}
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!