List of usage examples for org.w3c.dom NamedNodeMap item
public Node item(int index);
index
th item in the map. From source file:net.sf.jclal.experiment.ExperimentBuilder.java
private int expandAttributesIterateAtributes(Element element, int[] configurationSchema) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeValue().equals("multi")) { NodeList list = element.getElementsByTagName(attribute.getNodeName()); for (int j = 0; j < configurationSchema.length; j++) { if (configurationSchema[j] != -1) { attribute.setNodeValue(list.item(configurationSchema[j]).getFirstChild().getNodeValue()); configurationSchema[j] = -1; break; }//from www . j a v a 2 s.c o m } list = element.getChildNodes(); for (int j = 0; j < list.getLength(); j++) { if (list.item(j).getNodeName().equals(attribute.getNodeName())) { element.removeChild(list.item(j)); } } return 1; } } return 0; }
From source file:net.sf.jclal.experiment.ExperimentBuilder.java
private int expandElementsIterateAtributes(Element element, int[] configurationSchema) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeName().equals("multi")) { NodeList list = element.getElementsByTagName(element.getNodeName()); for (int j = 0; j < configurationSchema.length; j++) { if (configurationSchema[j] != -1) { element.getParentNode().replaceChild(list.item(configurationSchema[j]), element); configurationSchema[j] = -1; break; }// w w w . j a v a2s . com } list = element.getChildNodes(); for (int j = 0; j < list.getLength(); j++) { if (list.item(j).getNodeName().equals(attribute.getNodeName())) { element.removeChild(list.item(j)); } } return 1; } } return 0; }
From source file:DOM2SAX.java
/** * Writes a node using the given writer. * @param node node to serialize/*from w w w . j a v a2s . c o m*/ * @throws SAXException In case of a problem while writing XML */ private void writeNode(Node node) throws SAXException { if (node == null) { return; } switch (node.getNodeType()) { case Node.ATTRIBUTE_NODE: // handled by ELEMENT_NODE case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.NOTATION_NODE: // These node types are ignored!!! break; case Node.CDATA_SECTION_NODE: final String cdata = node.getNodeValue(); if (lexicalHandler != null) { lexicalHandler.startCDATA(); contentHandler.characters(cdata.toCharArray(), 0, cdata.length()); lexicalHandler.endCDATA(); } else { // in the case where there is no lex handler, we still // want the text of the cdate to make its way through. contentHandler.characters(cdata.toCharArray(), 0, cdata.length()); } break; case Node.COMMENT_NODE: // should be handled!!! if (lexicalHandler != null) { final String value = node.getNodeValue(); lexicalHandler.comment(value.toCharArray(), 0, value.length()); } break; case Node.DOCUMENT_NODE: contentHandler.startDocument(); Node next = node.getFirstChild(); while (next != null) { writeNode(next); next = next.getNextSibling(); } contentHandler.endDocument(); break; case Node.ELEMENT_NODE: String prefix; List pushedPrefixes = new java.util.ArrayList(); final AttributesImpl attrs = new AttributesImpl(); final NamedNodeMap map = node.getAttributes(); final int length = map.getLength(); // Process all namespace declarations for (int i = 0; i < length; i++) { final Node attr = map.item(i); final String qnameAttr = attr.getNodeName(); // Ignore everything but NS declarations here if (qnameAttr.startsWith(XMLNS_PREFIX)) { final String uriAttr = attr.getNodeValue(); final int colon = qnameAttr.lastIndexOf(':'); prefix = (colon > 0) ? qnameAttr.substring(colon + 1) : EMPTYSTRING; if (startPrefixMapping(prefix, uriAttr)) { pushedPrefixes.add(prefix); } } } // Process all other attributes for (int i = 0; i < length; i++) { final Node attr = map.item(i); final String qnameAttr = attr.getNodeName(); // Ignore NS declarations here if (!qnameAttr.startsWith(XMLNS_PREFIX)) { final String uriAttr = attr.getNamespaceURI(); // Uri may be implicitly declared if (uriAttr != null) { final int colon = qnameAttr.lastIndexOf(':'); prefix = (colon > 0) ? qnameAttr.substring(0, colon) : EMPTYSTRING; if (startPrefixMapping(prefix, uriAttr)) { pushedPrefixes.add(prefix); } } // Add attribute to list attrs.addAttribute(attr.getNamespaceURI(), getLocalName(attr), qnameAttr, "CDATA", attr.getNodeValue()); } } // Now process the element itself final String qname = node.getNodeName(); final String uri = node.getNamespaceURI(); final String localName = getLocalName(node); // Uri may be implicitly declared if (uri != null) { final int colon = qname.lastIndexOf(':'); prefix = (colon > 0) ? qname.substring(0, colon) : EMPTYSTRING; if (startPrefixMapping(prefix, uri)) { pushedPrefixes.add(prefix); } } // Generate SAX event to start element contentHandler.startElement(uri, localName, qname, attrs); // Traverse all child nodes of the element (if any) next = node.getFirstChild(); while (next != null) { writeNode(next); next = next.getNextSibling(); } // Generate SAX event to close element contentHandler.endElement(uri, localName, qname); // Generate endPrefixMapping() for all pushed prefixes final int nPushedPrefixes = pushedPrefixes.size(); for (int i = 0; i < nPushedPrefixes; i++) { endPrefixMapping((String) pushedPrefixes.get(i)); } break; case Node.PROCESSING_INSTRUCTION_NODE: contentHandler.processingInstruction(node.getNodeName(), node.getNodeValue()); break; case Node.TEXT_NODE: final String data = node.getNodeValue(); contentHandler.characters(data.toCharArray(), 0, data.length()); break; default: //nop } }
From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java
public static void handleElement(Element elt, JSONObject obj, boolean ignoreStepIds, boolean useType) throws JSONException { String key = elt.getTagName(); JSONObject value = new JSONObject(); NodeList nl = elt.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i);//from w w w . jav a2s . com if (node instanceof Element) { Element child = (Element) node; Object childValue = useType ? getValue(child, ignoreStepIds, useType) : null; if (childValue != null) { value.accumulate(child.getTagName(), childValue); } else { handleElement(child, value, ignoreStepIds, useType); } } } JSONObject attr = new JSONObject(); NamedNodeMap nnm = elt.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { Node node = nnm.item(i); if (ignoreStepIds && (node.getNodeName() != "step_id")) { attr.accumulate(node.getNodeName(), node.getNodeValue()); } } if (value.length() == 0) { String content = elt.getTextContent(); if (attr.length() == 0) { obj.accumulate(key, content); } else { value.accumulate("text", content); } } if (attr.length() != 0) { value.accumulate("attr", attr); } if (value.length() != 0) { obj.accumulate(key, value); } }
From source file:com.nridge.core.base.io.xml.DocumentXML.java
private Document loadDocument(Element anElement) throws IOException { Node nodeItem;// w w w.ja v a2 s. c o m Attr nodeAttr; Document document; Element nodeElement; String nodeName, nodeValue; String docName = anElement.getAttribute("name"); String typeName = anElement.getAttribute("type"); String docTitle = anElement.getAttribute("title"); String schemaVersion = anElement.getAttribute("schemaVersion"); if ((StringUtils.isNotEmpty(typeName)) && (StringUtils.isNotEmpty(schemaVersion))) document = new Document(typeName); else document = new Document("Unknown"); if (StringUtils.isNotEmpty(docName)) document.setName(docName); if (StringUtils.isNotEmpty(docTitle)) document.setName(docTitle); 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, "title")) || (StringUtils.equalsIgnoreCase(nodeName, "schemaVersion"))) continue; else document.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 (StringUtils.equalsIgnoreCase(nodeName, IO.XML_TABLE_NODE_NAME)) { nodeElement = (Element) nodeItem; DataTableXML dataTableXML = new DataTableXML(); dataTableXML.load(nodeElement); document.setTable(dataTableXML.getTable()); } else if (StringUtils.equalsIgnoreCase(nodeName, IO.XML_RELATED_NODE_NAME)) { nodeElement = (Element) nodeItem; loadRelated(document, nodeElement); } else if (StringUtils.equalsIgnoreCase(nodeName, IO.XML_ACL_NODE_NAME)) { nodeElement = (Element) nodeItem; loadACL(document, nodeElement); } } return document; }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static boolean hasContentAttributes(Element elm) { NamedNodeMap attributes = elm.getAttributes(); for (int c = 0; c < attributes.getLength(); c++) { Node item = attributes.item(c); String ns = item.getNamespaceURI(); if (!ns.equals(Constants.XML_NS) // && !ns.equals( Constants.XSI_NS ) && !ns.equals( // Constants.XSI_NS_2000 ) // && !ns.equals( Constants.XSD_NS ) )//from w w w . jav a2 s . co m return true; } return false; }
From source file:spec.schema.SchemaCurrent_TO_2008_02_Test.java
/** * Checks if the <code>Image</code> tag was correctly transformed. * //from w w w . j a va2 s . c om * @param destNode The node from the transformed file. * @param srcNode The Image node from the source file */ private void checkImageNode(Node destNode, Node srcNode) { assertNotNull(destNode); assertNotNull(srcNode); NamedNodeMap attributesSrc = srcNode.getAttributes(); String nameSrc = ""; String idSrc = ""; Node n; String name; for (int i = 0; i < attributesSrc.getLength(); i++) { n = attributesSrc.item(i); name = n.getNodeName(); if (name.equals(XMLWriter.ID_ATTRIBUTE)) idSrc = n.getNodeValue(); else if (name.equals(XMLWriter.NAME_ATTRIBUTE)) nameSrc = n.getNodeValue(); } // compare the stored values for ID and Name attributes // to those 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.ID_ATTRIBUTE)) assertEquals(n.getNodeValue(), idSrc); else if (name.equals(XMLWriter.NAME_ATTRIBUTE)) assertEquals(n.getNodeValue(), nameSrc); } } // Find the pixels node in the input image node // (if more than one last will be found) Node pixelsNode = null; NodeList list = srcNode.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { n = list.item(i); if (n != null) { name = n.getNodeName(); if (name.contains(XMLWriter.PIXELS_TAG)) pixelsNode = n; } } // Find the pixels node in the output image node // (if more than one this will be incorrect) list = destNode.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { n = list.item(i); if (n != null) { name = n.getNodeName(); if (name.contains(XMLWriter.PIXELS_TAG)) // - compare the found node to the input node stored above checkPixelsNode(n, pixelsNode); } } }
From source file:com.qcadoo.view.internal.xml.ViewDefinitionParserImpl.java
@Override public ComponentOption parseOption(final Node optionNode) { Map<String, String> attributes = new HashMap<String, String>(); NamedNodeMap attributesNodes = optionNode.getAttributes(); for (int i = 0; i < attributesNodes.getLength(); i++) { attributes.put(attributesNodes.item(i).getNodeName(), attributesNodes.item(i).getNodeValue()); }/* w w w. j ava2s. c o m*/ String type = getStringAttribute(optionNode, "type"); if (type == null) { type = getStringAttribute(optionNode, "xsi:type"); } return new ComponentOption(type, attributes); }
From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionParser.java
private Condition parsePlayerCondition(Node n, Object template) { Condition cond = null;/*from w ww. j a v a 2 s . c o m*/ NamedNodeMap attrs = n.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node a = attrs.item(i); Condition condOr = null; for (String nodeValue : StringUtils.split(getNodeValue(a.getNodeValue(), template), "|")) condOr = joinOr(condOr, parsePlayerCondition(a.getNodeName(), nodeValue)); cond = joinAnd(cond, condOr); } if (cond == null) throw new IllegalStateException("Empty <player> condition"); return cond; }
From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionParser.java
private Condition parseTargetCondition(Node n, Object template) { Condition cond = null;/*w w w . j ava 2s.c o m*/ NamedNodeMap attrs = n.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node a = attrs.item(i); Condition condOr = null; for (String nodeValue : StringUtils.split(getNodeValue(a.getNodeValue(), template), "|")) condOr = joinOr(condOr, parseTargetCondition(a.getNodeName(), nodeValue)); cond = joinAnd(cond, condOr); } if (cond == null) throw new IllegalStateException("Empty <target> condition"); return cond; }