@Override public int getAttributeCount() { if (currentNode == null) { return -1; } return currentNode.getAttributes().getLength(); }
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; }
private int extractAttributeIntValue(Node node, String attribute, int defaultValue) { try { NamedNodeMap attributes = node.getAttributes(); if (attributes.getLength() > 0) { Node attributeNode = attributes.getNamedItem(attribute); if (attributeNode != null) { return Integer.parseInt(attributeNode.getNodeValue()); } } } catch (NumberFormatException ignored) { // we assume the manifest is well-formed } return defaultValue; }
public static Map<String, Object> loadAttributes(Element e) { Map<String, Object> map = new HashMap<String, Object>(); NamedNodeMap nm = e.getAttributes(); for (int j = 0; j < nm.getLength(); j++) { Node n = nm.item(j); if (n instanceof Attr) { Attr attr = (Attr) n; map.put(attr.getName(), attr.getNodeValue()); } } return map; }
/** * Look up the index of an attribute by raw XML 1.0 name. * * @param qName The qualified (prefixed) name. * @return The index of the attribute, or -1 if it does not * appear in the list. */ public int getIndex(String qName) { for(int i=m_attrs.getLength()-1;i>=0;--i) { Node a=m_attrs.item(i); if(a.getNodeName().equals(qName) ) return i; } return -1; } }
Node getAttributeAt(int index) { if (currentNode == null) { throw new IndexOutOfBoundsException(String.valueOf(index)); } NamedNodeMap map = currentNode.getAttributes(); if (index >= map.getLength()) { throw new IndexOutOfBoundsException(String.valueOf(index)); } return map.item(index); }
protected void parseRule(Node root) throws Exception { if(root.getNodeType() != Node.ELEMENT_NODE) return; NamedNodeMap attrs=root.getAttributes(); if(attrs == null || attrs.getLength() == 0) return; Attr name_attr=(Attr)attrs.getNamedItem(NAME), classname_attr=(Attr)attrs.getNamedItem(CLASS), interval_attr=(Attr)attrs.getNamedItem(INTERVAL); Class<Rule> clazz=Util.loadClass(classname_attr.getValue(), getClass()); Rule rule=clazz.newInstance(); long interval=Long.parseLong(interval_attr.getValue()); installRule(name_attr.getValue(), interval, rule); }
public int getAttributeCount() { return currentElement.getAttributes().getLength(); }
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()); } }
public static String attr(Element el, String... attr) { NamedNodeMap nnm = el.getAttributes(); for(int i = 0; i != nnm.getLength(); ++i) { Node node = nnm.item(i); if (node instanceof Attr) { Attr a = (Attr) node; for(String at: attr) { if (a.getName().equalsIgnoreCase(at)) { return a.getValue(); } } } } return null; } }
/** * Look up the index of an attribute by raw XML 1.0 name. * * @param qName The qualified (prefixed) name. * @return The index of the attribute, or -1 if it does not * appear in the list. */ public int getIndex(String qName) { for(int i=m_attrs.getLength()-1;i>=0;--i) { Node a=m_attrs.item(i); if(a.getNodeName().equals(qName) ) return i; } return -1; } }
protected void visitAttributeNodes(XmlNode node, Node domNode, RuleContext ctx) { NamedNodeMap attributes = domNode.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { visit(node, (Attr) attributes.item(i), ctx); } } }
private static boolean isDefaultHttpConfig(Element httpElt) { return httpElt.getChildNodes().getLength() == 0 && httpElt.getAttributes().getLength() == 0; }
/** * 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; }
/** * Parse the supplied {@link Element} and populate the supplied * {@link BeanDefinitionBuilder} as required. * <p>This implementation maps any attributes present on the * supplied element to {@link org.springframework.beans.PropertyValue} * instances, and * {@link BeanDefinitionBuilder#addPropertyValue(String, Object) adds them} * to the * {@link org.springframework.beans.factory.config.BeanDefinition builder}. * <p>The {@link #extractPropertyName(String)} method is used to * reconcile the name of an attribute with the name of a JavaBean * property. * @param element the XML element being parsed * @param builder used to define the {@code BeanDefinition} * @see #extractPropertyName(String) */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); if (isEligibleAttribute(attribute, parserContext)) { String propertyName = extractPropertyName(attribute.getLocalName()); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); builder.addPropertyValue(propertyName, attribute.getValue()); } } postProcess(builder, element); }
/** * Look up the index of an attribute by raw XML 1.0 name. * * @param qName The qualified (prefixed) name. * @return The index of the attribute, or -1 if it does not * appear in the list. */ public int getIndex(String qName) { for(int i=m_attrs.getLength()-1;i>=0;--i) { Node a=m_attrs.item(i); if(a.getNodeName().equals(qName) ) return i; } return -1; } }
/** * Constructor. * * @param parent the parent DOM element for the attributes. */ AttributeIterator (Node parent) { this.map = parent.getAttributes(); this.pos = 0; for (int i = this.map.getLength()-1; i >= 0; i--) { Node node = map.item(i); if (! "http://www.w3.org/2000/xmlns/".equals(node.getNamespaceURI())) { this.lastAttribute = i; break; } } }