List of usage examples for org.w3c.dom NamedNodeMap getLength
public int getLength();
From source file:com.sqewd.os.maracache.core.Config.java
private ConfigPath load(ConfigNode parent, Element elm) throws ConfigException { if (parent instanceof ConfigPath) { // Check if there are any attributes. // Attributes are treated as Value nodes. if (elm.hasAttributes()) { NamedNodeMap map = elm.getAttributes(); if (map.getLength() > 0) { for (int ii = 0; ii < map.getLength(); ii++) { Node n = map.item(ii); ((ConfigPath) parent).addValueNode(n.getNodeName(), n.getNodeValue()); }//w w w. j av a 2 s. c o m } } if (elm.hasChildNodes()) { NodeList children = elm.getChildNodes(); for (int ii = 0; ii < children.getLength(); ii++) { Node cn = children.item(ii); if (cn.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) cn; if (e.hasChildNodes()) { int nc = 0; for (int jj = 0; jj < e.getChildNodes().getLength(); jj++) { Node ccn = e.getChildNodes().item(jj); // Read the text node if there is any. if (ccn.getNodeType() == Node.TEXT_NODE) { String n = e.getNodeName(); String v = ccn.getNodeValue(); if (!StringUtils.isEmpty(v.trim())) ((ConfigPath) parent).addValueNode(n, v); nc++; } } // Make sure this in not a text only node. if (e.getChildNodes().getLength() > nc) { // Check if this is a parameter node. Parameters are treated differently. if (e.getNodeName().compareToIgnoreCase(ConfigParams.NODE_NAME) == 0) { ConfigParams cp = ((ConfigPath) parent).addParamNode(); setParams(cp, e); } else { ConfigPath cp = ((ConfigPath) parent).addPathNode(e.getNodeName()); load(cp, e); } } } } } } } return (ConfigPath) parent; }
From source file:com.limegroup.gnutella.metadata.audio.reader.WRMXML.java
/** * Parses the attributes of a given node. * 'parentNodeName' is the parent node of this child, and child is the node * which the attributes are part of./* w w w.ja v a 2 s .co m*/ * Attributes are sent to parseChild for parsing. */ protected void parseAttributes(String parentNodeName, Node child) { NamedNodeMap nnm = child.getAttributes(); String name = child.getNodeName(); for (int i = 0; i < nnm.getLength(); i++) { Node attribute = nnm.item(i); String attrName = attribute.getNodeName(); String attrValue = attribute.getNodeValue(); if (attrValue == null) continue; attrValue = attrValue.trim(); if (attrValue.equals("")) continue; parseChild(parentNodeName, name, attrName, attrValue); } }
From source file:org.javelin.sws.ext.bind.jaxb.JaxbTest.java
@Test public void namespacesOfAttributes() throws Exception { XMLEventReader reader = XMLInputFactory.newFactory().createXMLEventReader( new ClassPathResource("org/javelin/sws/ext/bind/jaxb/context6/1.xml").getInputStream()); reader.nextEvent();/*from w w w . jav a 2 s . com*/ StartElement start = reader.nextEvent().asStartElement(); for (Iterator<?> it = start.getAttributes(); it.hasNext();) { System.out.println(((Attribute) it.next()).getName()); } System.out.println("---"); reader = XMLInputFactory.newFactory().createXMLEventReader( new ClassPathResource("org/javelin/sws/ext/bind/jaxb/context6/2.xml").getInputStream()); reader.nextEvent(); start = reader.nextEvent().asStartElement(); for (Iterator<?> it = start.getAttributes(); it.hasNext();) { System.out.println(((Attribute) it.next()).getName()); } System.out.println("---"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc1 = dbf.newDocumentBuilder().parse(new InputSource( new ClassPathResource("org/javelin/sws/ext/bind/jaxb/context6/1.xml").getInputStream())); NamedNodeMap attributes1 = doc1.getDocumentElement().getAttributes(); for (int i = 0; i < attributes1.getLength(); i++) System.out.println(((org.w3c.dom.Attr) attributes1.item(i)).getName() + " (" + ((org.w3c.dom.Attr) attributes1.item(i)).getNamespaceURI() + ")"); System.out.println("---"); doc1 = dbf.newDocumentBuilder().parse(new InputSource( new ClassPathResource("org/javelin/sws/ext/bind/jaxb/context6/2.xml").getInputStream())); attributes1 = doc1.getDocumentElement().getAttributes(); for (int i = 0; i < attributes1.getLength(); i++) System.out.println(((org.w3c.dom.Attr) attributes1.item(i)).getName() + " (" + ((org.w3c.dom.Attr) attributes1.item(i)).getNamespaceURI() + ")"); System.out.println("---"); doc1 = dbf.newDocumentBuilder().parse(new InputSource( new ClassPathResource("org/javelin/sws/ext/bind/jaxb/context6/3.xml").getInputStream())); attributes1 = doc1.getDocumentElement().getAttributes(); for (int i = 0; i < attributes1.getLength(); i++) System.out.println(((org.w3c.dom.Attr) attributes1.item(i)).getName() + " (" + ((org.w3c.dom.Attr) attributes1.item(i)).getNamespaceURI() + ")"); }
From source file:com.swdouglass.joid.consumer.Discoverer.java
private String nodeToString(Node inNode) { StringBuilder sb = new StringBuilder(); sb.append("[Node: name="); sb.append(inNode.getNodeName());//www. java2 s. c om if (inNode.hasAttributes()) { sb.append(", attributes={"); NamedNodeMap nnmap = inNode.getAttributes(); for (int i = 0; i < nnmap.getLength(); i++) { sb.append(nnmap.item(i).getNodeName()); sb.append("="); sb.append(nnmap.item(i).getNodeValue()); sb.append(" "); } } sb.append("}]"); return sb.toString(); }
From source file:com.predic8.membrane.core.config.spring.AbstractParser.java
protected void setProperties(String prop, Element e, BeanDefinitionBuilder builder) { NamedNodeMap attributes = e.getAttributes(); HashMap<String, String> attrs = new HashMap<String, String>(); for (int i = 0; i < attributes.getLength(); i++) { Attr item = (Attr) attributes.item(i); if (item.getLocalName() != null) attrs.put(item.getLocalName(), item.getValue()); }// www . j a va 2 s .c o m builder.addPropertyValue(prop, attrs); }
From source file:de.fhg.iais.asc.xslt.binaries.DownloadAndScale.java
private void handleSetParameters(Node item) { NamedNodeMap attrMap = item.getAttributes(); int i = attrMap.getLength(); while (i-- > 0) { Node attrNode = attrMap.item(i); this.parameters.put(attrNode.getNodeName(), attrNode.getNodeValue()); }//from www . j a va 2 s . com }
From source file:au.gov.ga.earthsci.bookmark.properties.layer.LayersPropertyPersister.java
@Override public IBookmarkProperty createFromXML(String type, Element propertyElement) { Validate.isTrue(LayersProperty.TYPE.equals(type), INVALID_TYPE_MSG); Validate.notNull(propertyElement, "A property element is required"); //$NON-NLS-1$ LayersProperty result = new LayersProperty(); for (Element state : XmlUtil.getElements(propertyElement, LAYER_XPATH, null)) { // state.getAttributes() String id = XMLUtil.getText(state, ID_ATTRIBUTE_XPATH); Double opacity = XMLUtil.getDouble(state, OPACITY_ATTRIBUTE_XPATH, 1.0d); NamedNodeMap attrs = state.getAttributes(); if (id != null) { List<Pair<String, String>> pairs = new ArrayList<Pair<String, String>>(); for (int i = 0; i < attrs.getLength(); i++) { String key = attrs.item(i).getNodeName(); String value = attrs.item(i).getNodeValue(); if (!key.equals(ID_ATTRIBUTE_NAME)) { pairs.add(new ImmutablePair<String, String>(key, value)); }/*from w ww .jav a 2 s .c o m*/ } result.addLayer(id, pairs.toArray(new Pair[0])); } } return result; }
From source file:com.nridge.core.base.io.xml.DataFieldXML.java
public DataField load(Element anElement) throws IOException { Attr nodeAttr;//from w w w . j a va 2 s . c o m Node nodeItem; DataField dataField; Element nodeElement; Field.Type fieldType; String nodeName, nodeValue; String attrValue = anElement.getAttribute("name"); if (StringUtils.isNotEmpty(attrValue)) { String fieldName = attrValue; attrValue = anElement.getAttribute("type"); if (StringUtils.isNotEmpty(attrValue)) fieldType = Field.stringToType(attrValue); else fieldType = Field.Type.Text; dataField = new DataField(fieldType, fieldName); NamedNodeMap namedNodeMap = anElement.getAttributes(); int attrCount = namedNodeMap.getLength(); for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) { nodeAttr = (Attr) namedNodeMap.item(attrOffset); nodeName = nodeAttr.getNodeName(); nodeValue = nodeAttr.getNodeValue(); if (StringUtils.isNotEmpty(nodeValue)) { if ((StringUtils.equalsIgnoreCase(nodeName, "name")) || (StringUtils.equalsIgnoreCase(nodeName, "type")) || (StringUtils.equalsIgnoreCase(nodeName, "rangeType"))) continue; else if (StringUtils.equalsIgnoreCase(nodeName, "title")) dataField.setTitle(nodeValue); else if (StringUtils.equalsIgnoreCase(nodeName, "isMultiValue")) dataField.setMultiValueFlag(StrUtl.stringToBoolean(nodeValue)); else if (StringUtils.equalsIgnoreCase(nodeName, "displaySize")) dataField.setDisplaySize(Field.createInt(nodeValue)); else if (StringUtils.equalsIgnoreCase(nodeName, "sortOrder")) dataField.setSortOrder(Field.Order.valueOf(nodeValue)); else if (StringUtils.equalsIgnoreCase(nodeName, "defaultValue")) dataField.setDefaultValue(nodeValue); else dataField.addFeature(nodeName, nodeValue); } } String rangeType = anElement.getAttribute("rangeType"); if (StringUtils.isNotEmpty(rangeType)) { NodeList nodeList = anElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { nodeItem = nodeList.item(i); if (nodeItem.getNodeType() != Node.ELEMENT_NODE) continue; nodeName = nodeItem.getNodeName(); if (StringUtils.equalsIgnoreCase(nodeName, "Range")) { nodeElement = (Element) nodeItem; dataField.setRange(mRangeXML.load(nodeElement)); } else if (StringUtils.equalsIgnoreCase(nodeName, "Value")) { nodeValue = XMLUtl.getNodeStrValue(nodeItem); String mvDelimiter = dataField.getFeature(Field.FEATURE_MV_DELIMITER); if (StringUtils.isNotEmpty(mvDelimiter)) dataField.expand(nodeValue, mvDelimiter.charAt(0)); else dataField.expand(nodeValue); } } } else { nodeItem = (Node) anElement; if (dataField.isFeatureTrue(Field.FEATURE_IS_CONTENT)) nodeValue = XMLUtl.getNodeCDATAValue(nodeItem); else nodeValue = XMLUtl.getNodeStrValue(nodeItem); if (dataField.isMultiValue()) { String mvDelimiter = dataField.getFeature(Field.FEATURE_MV_DELIMITER); if (StringUtils.isNotEmpty(mvDelimiter)) dataField.expand(nodeValue, mvDelimiter.charAt(0)); else dataField.expand(nodeValue); } else dataField.setValue(nodeValue); } } else dataField = null; return dataField; }
From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java
private void copyParing(Document paring, Node response) throws Exception { Node paringElement = response.appendChild(response.getOwnerDocument().createElement("paring")); Node kehaNode = response.getOwnerDocument().importNode(paring.getDocumentElement(), true); NamedNodeMap attrs = kehaNode.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { paringElement.getAttributes().setNamedItem(attrs.item(i).cloneNode(true)); }/*from w w w . ja v a2 s .c o m*/ while (kehaNode.hasChildNodes()) { paringElement.appendChild(kehaNode.getFirstChild()); } }
From source file:com.icesoft.jasper.xmlparser.ParserUtils.java
/** * Create and return a TreeNode that corresponds to the specified Node, * including processing all of the attributes and children nodes. * * @param parent The parent TreeNode (if any) for the new TreeNode * @param node The XML document Node to be converted *//*from w ww . ja va 2s.c om*/ protected TreeNode convert(TreeNode parent, Node node) { // Construct a new TreeNode for this node TreeNode treeNode = new TreeNode(node.getNodeName(), parent); // Convert all attributes of this node NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { int n = attributes.getLength(); for (int i = 0; i < n; i++) { Node attribute = attributes.item(i); treeNode.addAttribute(attribute.getNodeName(), attribute.getNodeValue()); } } // Create and attach all children of this node NodeList children = node.getChildNodes(); if (children != null) { int n = children.getLength(); for (int i = 0; i < n; i++) { Node child = children.item(i); if (child instanceof Comment) continue; if (child instanceof Text) { String body = ((Text) child).getData(); if (body != null) { body = body.trim(); if (body.length() > 0) treeNode.setBody(body); } } else { TreeNode treeChild = convert(treeNode, child); } } } // Return the completed TreeNode graph return (treeNode); }