List of usage examples for org.w3c.dom NamedNodeMap item
public Node item(int index);
index
th item in the map. From source file:eionet.gdem.conversion.odf.ODFSpreadsheetAnalyzer.java
/** * Finds the namespace prefixes associated with OpenDocument, Dublin Core, and OpenDocument meta elements. * This function presumes that all the namespaces are in the root element. If they aren't, this breaks. * * @param rootElement/*from w w w. j a v a 2s . c o m*/ * the root element of the document. */ protected void findNamespaces(Element rootElement) { NamedNodeMap attributes; Node node; String value; attributes = rootElement.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { node = attributes.item(i); value = node.getNodeValue(); if (value.equals(DC_URI)) { dcNamespace = extractNamespace(node.getNodeName()); } else if (value.equals(TABLE_URI)) { tableNamespace = extractNamespace(node.getNodeName()); } else if (value.equals(TEXT_URI)) { textNamespace = extractNamespace(node.getNodeName()); } else if (value.equals(OPENDOCUMENT_URI)) { officeNamespace = extractNamespace(node.getNodeName()); } } }
From source file:org.gvnix.dynamic.configuration.roo.addon.config.XmlDynamicConfiguration.java
/** * Create the dynamic properties related to this node attributes. * // w w w . ja v a2 s .c om * @param node Node to add to list * @param xpath Xpath expression of this node * @return Dynamic property list */ protected DynPropertyList getPropertyAttributes(Node node, String xpath) { DynPropertyList dynProps = new DynPropertyList(); // Iterate all node attributes, if exists NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { for (int j = 0; j < attrs.getLength(); j++) { // Get attribute and it name Node attr = attrs.item(j); String attrName = attr.getNodeName(); // Create dynamic property, except attribute references if (!attrName.equals(REF_ATTRIBUTE_NAME)) { dynProps.add(new DynProperty( xpath + XPATH_ARRAY_PREFIX + XPATH_ATTRIBUTE_PREFIX + attrName + XPATH_ARRAY_SUFIX, attr.getNodeValue())); } } } return dynProps; }
From source file:spec.schema.SchemaCurrent_TO_2008_02_Test.java
/** * Checks if the <code>Image</code> tag was correctly transformed. * /* ww w .jav a 2 s .c o m*/ * @param destNode The node from the transformed file. * @param srcNode The Image node from the source file */ private void checkBinDataNode(Node destNode, Node srcNode) { assertNotNull(destNode); assertNotNull(srcNode); // store the values for Compression attribute on the input node NamedNodeMap attributesSrc = srcNode.getAttributes(); String compression = ""; Node n; String name; for (int i = 0; i < attributesSrc.getLength(); i++) { n = attributesSrc.item(i); name = n.getNodeName(); if (name.equals(XMLWriter.COMPRESSION_ATTRIBUTE)) compression = n.getNodeValue(); } // compare the stored value for the Compression attribute // to that on the output node NamedNodeMap attributes = destNode.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { n = attributes.item(i); if (n != null) { name = n.getNodeName(); if (name.equals(XMLWriter.COMPRESSION_ATTRIBUTE)) { assertEquals(n.getNodeValue(), compression); } } } // compare the contents of the BinData node assertEquals(destNode.getTextContent(), srcNode.getTextContent()); }
From source file:com.nridge.core.base.io.xml.DocumentReplyXML.java
/** * Parses an XML DOM element and loads it into a document list. * * @param anElement DOM element.// ww w. ja v a2s. c om * @throws java.io.IOException I/O related exception. */ @Override public void load(Element anElement) throws IOException { Attr nodeAttr; Node nodeItem; Document document; Element nodeElement; DocumentXML documentXML; String nodeName, nodeValue; nodeName = anElement.getNodeName(); if (StringUtils.equalsIgnoreCase(nodeName, IO.XML_REPLY_NODE_NAME)) { mField.clearFeatures(); String attrValue = anElement.getAttribute(Doc.FEATURE_OP_STATUS_CODE); if (StringUtils.isNotEmpty(attrValue)) { mField.setName(Doc.FEATURE_OP_STATUS_CODE); mField.setValue(attrValue); 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, Doc.FEATURE_OP_STATUS_CODE)) && (!StringUtils.equalsIgnoreCase(nodeName, Doc.FEATURE_OP_COUNT))) mField.addFeature(nodeName, nodeValue); } } } NodeList nodeList = anElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { nodeItem = nodeList.item(i); if (nodeItem.getNodeType() != Node.ELEMENT_NODE) continue; // We really do not know how the node was named, so we will just accept it. nodeElement = (Element) nodeItem; documentXML = new DocumentXML(); documentXML.load(nodeElement); document = documentXML.getDocument(); if (document != null) mDocumentList.add(document); } } }
From source file:hudson.plugins.plot.XMLSeries.java
/*** * This is a fallback strategy for nodesets that include non numeric content * enabling users to create lists by selecting them such that names and * values share a common parent. If a node has attributes and is empty that * node will be re-enqueued as a parent to its attributes. * // w w w .j a v a 2 s.c o m * @param buildNumber * the build number * * @returns a list of PlotPoints where the label is the last non numeric * text content and the value is the last numeric text content for * each set of nodes under a given parent. ***/ private List<PlotPoint> coalesceTextnodesAsLabelsStrategy(NodeList nodeList, int buildNumber) { Map<Node, List<Node>> parentNodeMap = new HashMap<Node, List<Node>>(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (!parentNodeMap.containsKey(node.getParentNode())) { parentNodeMap.put(node.getParentNode(), new ArrayList<Node>()); } parentNodeMap.get(node.getParentNode()).add(node); } List<PlotPoint> retval = new ArrayList<PlotPoint>(); Queue<Node> parents = new ArrayDeque<Node>(parentNodeMap.keySet()); while (!parents.isEmpty()) { Node parent = parents.poll(); Double value = null; String label = null; for (Node child : parentNodeMap.get(parent)) { if (null == child.getTextContent() || child.getTextContent().trim().isEmpty()) { NamedNodeMap attrmap = child.getAttributes(); List<Node> attrs = new ArrayList<Node>(); for (int i = 0; i < attrmap.getLength(); i++) { attrs.add(attrmap.item(i)); } parentNodeMap.put(child, attrs); parents.add(child); } else if (new Scanner(child.getTextContent().trim()).hasNextDouble()) { value = new Scanner(child.getTextContent().trim()).nextDouble(); } else { label = child.getTextContent().trim(); } } if ((label != null) && (value != null)) { addValueToList(retval, new String(label), String.valueOf(value), buildNumber); } } return retval; }
From source file:net.sf.jclal.experiment.ExperimentBuilder.java
private int expandElementsIterateAttributes(Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeName().equals("multi")) { combinationBase.add(element.getElementsByTagName(element.getNodeName()).getLength()); return 1; }/*ww w . ja v a 2 s .c o m*/ } return 0; }
From source file:net.sf.jclal.experiment.ExperimentBuilder.java
private int expandAttributesIterateAttributes(Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeValue().equals("multi")) { combinationBase.add(element.getElementsByTagName(attribute.getNodeName()).getLength()); return 1; }// w w w . j av a 2 s.c om } return 0; }
From source file:com.nridge.core.base.io.xml.DataTableXML.java
/** * Parses an XML DOM element and loads it into a bag/table. * * @param anElement DOM element./*from w ww . j av a 2s .c om*/ * @throws java.io.IOException I/O related exception. */ @Override public void load(Element anElement) throws IOException { Node nodeItem; Attr nodeAttr; Element nodeElement; String nodeName, nodeValue, attrValue; attrValue = anElement.getAttribute("name"); if (StringUtils.isNotEmpty(attrValue)) mDataTable.setName(attrValue); 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")) mDataTable.addFeature(nodeName, nodeValue); } } 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 (nodeName.equalsIgnoreCase("Context")) { nodeElement = (Element) nodeItem; attrValue = nodeElement.getAttribute("start"); if (StringUtils.isNumeric(attrValue)) mContextStart = Integer.parseInt(attrValue); attrValue = nodeElement.getAttribute("limit"); if (StringUtils.isNumeric(attrValue)) mContextLimit = Integer.parseInt(attrValue); attrValue = nodeElement.getAttribute("total"); if (StringUtils.isNumeric(attrValue)) mContextTotal = Integer.parseInt(attrValue); } else if (nodeName.equalsIgnoreCase("Columns")) { nodeElement = (Element) nodeItem; DataBagXML dataBagXML = new DataBagXML(); dataBagXML.load(nodeElement); DataBag dataBag = dataBagXML.getBag(); dataBag.setName(mDataTable.getName()); mDataTable = new DataTable(dataBag); } else if (nodeName.equalsIgnoreCase("Rows")) { nodeElement = (Element) nodeItem; loadRows(nodeElement); } } }
From source file:net.algart.simagis.imageio.IIOMetadataToJsonConverter.java
private JSONObject treeToJson(Node node) throws JSONException { JSONObject result = new JSONObject(); result.put("name", node.getNodeName()); result.put("value", node.getNodeValue()); final NamedNodeMap nodeAttributes = node.getAttributes(); if (nodeAttributes != null) { final int length = nodeAttributes.getLength(); if (length > 0) { JSONObject attributes = new JSONObject(); for (int k = 0; k < length; k++) { final Node nodeAttr = nodeAttributes.item(k); attributes.put(nodeAttr.getNodeName(), nodeAttr.getNodeValue()); }/*from ww w . j a v a 2s. c om*/ result.put("attributes", attributes); } } JSONObject compactChildren = null; for (String childrenName : COMPACTED_SIMILAR_CHILDREN_NAMES) { compactChildren = compactTIFFSimilarNodes(node, childrenName); if (compactChildren != null) { break; } } if (compactChildren != null) { result.put("joinedNodes", compactChildren); } else { Node child = node.getFirstChild(); if (child != null) { JSONArray nodes = new JSONArray(); do { nodes.put(treeToJson(child)); child = child.getNextSibling(); } while (child != null); result.put("nodes", nodes); } } if (node instanceof IIOMetadataNode) { result.put("userObject", iioNodeUserObjectToJson((IIOMetadataNode) node)); } return result; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
private static void showDomNode(Node node, StringBuilder sb, int level) { if (sb == null) { // buffer not provided, return immediately return;// w w w . j a va 2 s .c o m } // indent for (int i = 0; i < level; i++) { sb.append(" "); } if (node == null) { sb.append("null\n"); } else { sb.append(node.getNodeName()); sb.append(" ("); NamedNodeMap attributes = node.getAttributes(); boolean broken = false; if (attributes != null) { for (int ii = 0; ii < attributes.getLength(); ii++) { Node attribute = attributes.item(ii); sb.append(attribute.getPrefix()); sb.append(":"); sb.append(attribute.getLocalName()); sb.append("='"); sb.append(attribute.getNodeValue()); sb.append("',"); if (attribute.getPrefix() == null && attribute.getLocalName().equals("xmlns") && (attribute.getNodeValue() == null || attribute.getNodeValue().isEmpty())) { broken = true; } } } sb.append(")"); if (broken) { sb.append(" *** WARNING: empty default namespace"); } sb.append("\n"); NodeList childNodes = node.getChildNodes(); for (int ii = 0; ii < childNodes.getLength(); ii++) { Node subnode = childNodes.item(ii); showDomNode(subnode, sb, level + 1); } } }