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; }
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); }
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; } }
@Override public Attribute next() { org.w3c.dom.Node attributeNode = attributes.item(index++); return new Attribute(XmlNodeWrapper.this, attributeNode.getNodeName(), attributeNode.getNodeValue()); }
public String getAttribute(int index) { return ((Attr) currentElement.getAttributes().item(index)).getValue(); }
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()); } }
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); } } }
public String getAttributeName(int index) { return decodeAttribute(((Attr) currentElement.getAttributes().item(index)).getName()); }
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()); } }
/** * 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; } } }
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; }
public void parseAttributes(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)) { String propertyName = attribute.getLocalName().endsWith(REF_SUFFIX) ? attribute.getLocalName() .substring(0, attribute.getLocalName() .length() - REF_SUFFIX.length()) : attribute.getLocalName(); propertyName = Conventions .attributeNameToPropertyName(propertyName); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from" + " 'extractPropertyName(String)': cannot be" + " null or empty."); if (attribute.getLocalName().endsWith(REF_SUFFIX)) { builder.addPropertyReference(propertyName, attribute.getValue()); } else { builder.addPropertyValue(propertyName, attribute.getValue()); } } } }