List of usage examples for org.w3c.dom NamedNodeMap item
public Node item(int index);
index
th item in the map. From source file:TreeDumper2.java
private void dumpElement(Element node, String indent) { System.out.println(indent + "ELEMENT: " + node.getTagName()); NamedNodeMap nm = node.getAttributes(); for (int i = 0; i < nm.getLength(); i++) dumpLoop(nm.item(i), indent + " "); }
From source file:org.shareok.data.plosdata.PlosApiDataImpl.java
private Map<String, String> getArticleMapData(Element ele) { Map<String, String> mapData = new HashMap<>(); NodeList eleChildren = ele.getChildNodes(); for (int childIndex = 0; childIndex < eleChildren.getLength(); childIndex++) { Node node = eleChildren.item(childIndex); String nodeName = node.getNodeName(); NamedNodeMap attributes = node.getAttributes(); if (attributes.getLength() > 0) { Node item = attributes.item(0); String attributeVal = item.getNodeValue(); String val = ""; if (nodeName.equals("arr")) { NodeList children = node.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { Node child = children.item(j); if (child.getNodeName().equals("str")) { val += child.getTextContent() + "; "; }/*from w ww .j a v a2 s .c o m*/ } } else { val = node.getTextContent(); } val = val.trim(); if (val.endsWith(";")) { val = val.substring(0, val.length() - 1); } if (attributeVal.equals("publication_date")) { attributeVal = "publication date"; try { val = DataHandlersUtil.convertPubTimeFormat(val); } catch (ParseException ex) { logger.error( "Cannot convert the publication time from yyyy-MM-dd'T'HH:mm:ss to yyyy-MM-dd format", ex); } } mapData.put(attributeVal, val); } } return mapData; }
From source file:com.krawler.esp.utils.mime.MimeTypesReader.java
/** Read Element named magic. */ private void readMagic(Element element, MimeType mimeType) { // element.getValue(); String offset = null;//from w w w .j a v a 2s. c o m String content = null; String type = null; NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); if (attr.getName().equals("offset")) { offset = attr.getValue(); } else if (attr.getName().equals("type")) { type = attr.getValue(); } else if (attr.getName().equals("value")) { content = attr.getValue(); } } if ((offset != null) && (content != null)) { mimeType.addMagic(Integer.parseInt(offset), type, content); } }
From source file:cn.edu.bit.whitesail.parser.HtmlParser.java
private void getLinks(Node node, List<URL> URLsToFill, String anchor) { URL u = null;/* ww w . j av a 2 s .c om*/ if (node.getNodeName().equalsIgnoreCase("a") || node.getNodeName().equalsIgnoreCase("link")) { NamedNodeMap map = node.getAttributes(); int length = map.getLength(); for (int i = 0; i < length; i++) { Node item = map.item(i); if (item.getNodeName().equalsIgnoreCase("href")) { u = URLFormat(item.getNodeValue(), anchor); if (null != u) { URLsToFill.add(u); } } } } Node child = node.getFirstChild(); while (child != null) { getLinks(child, URLsToFill, anchor); child = child.getNextSibling(); } }
From source file:com.apporiented.spring.override.GenericBeanDefinitionParser.java
/** * Parse the supplied {@link org.w3c.dom.Element} and populate the supplied * {@link org.springframework.beans.factory.support.BeanDefinitionBuilder} as required. * <p>This implementation maps any attributes present on the * supplied element to {@link org.springframework.beans.PropertyValue} * instances, and//from w w w. j av a 2 s .com * {@link org.springframework.beans.factory.support.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 parserContext the object encapsulating the current state of the parsing process * @param builder used to define the <code>BeanDefinition</code> * @see #extractPropertyName(String) */ protected final 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); String name = attribute.getLocalName(); if (isEligibleAttribute(name, parserContext)) { String propertyName = extractPropertyName(name); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); Object value; if (references.contains(propertyName)) { value = new RuntimeBeanReference(attribute.getValue()); } else { value = attribute.getValue(); } builder.addPropertyValue(propertyName, value); } } postProcess(builder, parserContext, element); }
From source file:com.apricot.eating.xml.XMLParser.java
public HashMap getAttributes(Node node) { NamedNodeMap map = node.getAttributes(); HashMap attrs = new HashMap(); for (int i = 0; i < map.getLength(); i++) { Node n = map.item(i); attrs.put(n.getNodeName(), n.getNodeValue()); n = null;/*from w w w .j ava 2 s.c om*/ } return attrs; }
From source file:com.qwazr.extractor.parser.ImageParser.java
private void browseNodes(String path, final Node root, final ParserFieldsBuilder result) { if (root == null) return;/*from w w w . j a v a2 s. c o m*/ switch (root.getNodeType()) { case Node.TEXT_NODE: result.add(ParserField.newString(path, null), root.getNodeValue()); break; case Node.ELEMENT_NODE: final NamedNodeMap nnm = root.getAttributes(); if (nnm != null) for (int i = 0; i < nnm.getLength(); i++) browseNodes(path, nnm.item(i), result); Node child = root.getFirstChild(); while (child != null) { browseNodes(path + "/" + child.getNodeName(), child, result); child = child.getNextSibling(); } break; case Node.ATTRIBUTE_NODE: path = path + "#" + root.getNodeName(); result.add(ParserField.newString(path, null), root.getNodeValue()); break; default: throw new NotImplementedException("Unknown attribute: " + root.getNodeType()); } }
From source file:edu.wustl.xipHost.hostLogin.STSLogin.java
void parseSamlAssertion(String xmlSamlAssertion) throws ParserConfigurationException, SAXException, IOException { InputStream is = new ByteArrayInputStream(xmlSamlAssertion.getBytes()); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(is); samlAssertionElement = doc.getDocumentElement(); //docELement to be returned to XUA to build XUAAssertion NodeList childNodes = samlAssertionElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode.getNodeName().equals("saml:AttributeStatement")) { NodeList attStatementNodes = childNode.getChildNodes(); for (int j = 0; j < attStatementNodes.getLength(); j++) { Node node = attStatementNodes.item(j); NamedNodeMap atts = node.getAttributes(); for (int k = 0; k < atts.getLength(); k++) { Node att = atts.item(k); if (att.getNodeValue().endsWith("GlobusCredential")) { NodeList globusCredNodes = node.getChildNodes(); String saml = globusCredNodes.item(0).getTextContent(); try { byte[] bytes = Base64.decode(saml); ByteArrayInputStream stream = new ByteArrayInputStream(bytes); globusCred = new GlobusCredential(stream); } catch (GlobusCredentialException e) { globusCred = null; logger.error(e, e); }//w ww. ja v a 2s.com } } } } } is.close(); }
From source file:com.krawler.esp.utils.mime.MimeTypesReader.java
/** Read Element named mime-type. */ private MimeType readMimeType(Element element) { String name = null;/*from w w w . j a v a 2s. c o m*/ String description = null; MimeType type = null; NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); if (attr.getName().equals("name")) { name = attr.getValue(); } else if (attr.getName().equals("description")) { description = attr.getValue(); } } if ((name == null) || (name.trim().equals(""))) { return null; } try { type = new MimeType(name); } catch (MimeTypeException mte) { // Mime Type not valid... just ignore it if (logger.isInfoEnabled()) { logger.info(mte.toString() + " ... Ignoring!"); } return null; } type.setDescription(description); NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element nodeElement = (Element) node; if (nodeElement.getTagName().equals("ext")) { readExt(nodeElement, type); } else if (nodeElement.getTagName().equals("magic")) { readMagic(nodeElement, type); } } } return type; }
From source file:org.focusns.common.web.page.config.xml.XmlPageFactory.java
private Map<String, String> getParameters(Element pageEle) { Map<String, String> parameters = new HashMap<String, String>(); NamedNodeMap nnm = pageEle.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { Node node = nnm.item(i); String paramName = node.getNodeName(); String paramValue = node.getNodeValue(); parameters.put(paramName, paramValue); }//from w w w .j a v a 2s . c o m return parameters; }