List of usage examples for org.w3c.dom NamedNodeMap item
public Node item(int index);
index
th item in the map. From source file:com.diversityarrays.dalclient.DalUtil.java
public static DalResponseRecord createFrom(String requestUrl, Node node) { DalResponseRecord result = new DalResponseRecord(requestUrl, node.getNodeName()); NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { int nAttributes = attributes.getLength(); for (int ai = 0; ai < nAttributes; ++ai) { Node attr = attributes.item(ai); result.rowdata.put(attr.getNodeName(), attr.getNodeValue()); }/*from w ww . ja v a 2 s. c o m*/ } NodeList childNodes = node.getChildNodes(); int nChildNodes = childNodes.getLength(); if (nChildNodes > 0) { for (int ci = 0; ci < nChildNodes; ++ci) { Node child = childNodes.item(ci); if (Node.ELEMENT_NODE == child.getNodeType()) { String childName = child.getNodeName(); Map<String, String> childMap = asRowdata(child); if (childMap != null) { result.addNestedData(childName, childMap); } } } } return result; }
From source file:TreeDumper2.java
private void dumpDocumentType(DocumentType node, String indent) { System.out.println(indent + "DOCUMENT_TYPE: " + node.getName()); if (node.getPublicId() != null) System.out.println(indent + " Public ID: " + node.getPublicId()); if (node.getSystemId() != null) System.out.println(indent + " System ID: " + node.getSystemId()); NamedNodeMap entities = node.getEntities(); if (entities.getLength() > 0) { for (int i = 0; i < entities.getLength(); i++) { dumpLoop(entities.item(i), indent + " "); }/* ww w . ja v a 2 s. com*/ } NamedNodeMap notations = node.getNotations(); if (notations.getLength() > 0) { for (int i = 0; i < notations.getLength(); i++) dumpLoop(notations.item(i), indent + " "); } }
From source file:XMLDocumentWriter.java
/** * Output the specified DOM Node object, printing it using the specified * indentation string/*from ww w .j ava2 s .c om*/ */ public void write(Node node, String indent) { // The output depends on the type of the node switch (node.getNodeType()) { case Node.DOCUMENT_NODE: { // If its a Document node Document doc = (Document) node; out.println(indent + "<?xml version='1.0'?>"); // Output header Node child = doc.getFirstChild(); // Get the first node while (child != null) { // Loop 'till no more nodes write(child, indent); // Output node child = child.getNextSibling(); // Get next node } break; } case Node.DOCUMENT_TYPE_NODE: { // It is a <!DOCTYPE> tag DocumentType doctype = (DocumentType) node; // Note that the DOM Level 1 does not give us information about // the the public or system ids of the doctype, so we can't output // a complete <!DOCTYPE> tag here. We can do better with Level 2. out.println("<!DOCTYPE " + doctype.getName() + ">"); break; } case Node.ELEMENT_NODE: { // Most nodes are Elements Element elt = (Element) node; out.print(indent + "<" + elt.getTagName()); // Begin start tag NamedNodeMap attrs = elt.getAttributes(); // Get attributes for (int i = 0; i < attrs.getLength(); i++) { // Loop through them Node a = attrs.item(i); out.print(" " + a.getNodeName() + "='" + // Print attr. name fixup(a.getNodeValue()) + "'"); // Print attr. value } out.println(">"); // Finish start tag String newindent = indent + " "; // Increase indent Node child = elt.getFirstChild(); // Get child while (child != null) { // Loop write(child, newindent); // Output child child = child.getNextSibling(); // Get next child } out.println(indent + "</" + // Output end tag elt.getTagName() + ">"); break; } case Node.TEXT_NODE: { // Plain text node Text textNode = (Text) node; String text = textNode.getData().trim(); // Strip off space if ((text != null) && text.length() > 0) // If non-empty out.println(indent + fixup(text)); // print text break; } case Node.PROCESSING_INSTRUCTION_NODE: { // Handle PI nodes ProcessingInstruction pi = (ProcessingInstruction) node; out.println(indent + "<?" + pi.getTarget() + " " + pi.getData() + "?>"); break; } case Node.ENTITY_REFERENCE_NODE: { // Handle entities out.println(indent + "&" + node.getNodeName() + ";"); break; } case Node.CDATA_SECTION_NODE: { // Output CDATA sections CDATASection cdata = (CDATASection) node; // Careful! Don't put a CDATA section in the program itself! out.println(indent + "<" + "![CDATA[" + cdata.getData() + "]]" + ">"); break; } case Node.COMMENT_NODE: { // Comments Comment c = (Comment) node; out.println(indent + "<!--" + c.getData() + "-->"); break; } default: // Hopefully, this won't happen too much! System.err.println("Ignoring node: " + node.getClass().getName()); break; } }
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()); }//from ww w . j a va2 s.co m builder.addPropertyValue(prop, attrs); }
From source file:org.jolokia.jvmagent.spring.config.ConfigBeanDefinitionParser.java
private Map<Object, Object> createConfigMap(NamedNodeMap attributes) { ManagedMap<Object, Object> map = new ManagedMap<Object, Object>(attributes.getLength()); map.setKeyTypeName("java.lang.String"); map.setValueTypeName("java.lang.String"); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); String name = attr.getName(); if (skipMap.contains(name)) { continue; }/*from ww w .ja v a2 s . c om*/ Object key = new TypedStringValue(name, String.class); Object value = new TypedStringValue(attr.getValue(), String.class); map.put(key, value); } return map; }
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 . j a v a 2 s .c o m 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: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)); }// w w w. j a va 2 s . co m } result.addLayer(id, pairs.toArray(new Pair[0])); } } return result; }
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 ww w .j a v a2 s . c o m*/ }
From source file:ca.mcgill.music.ddmal.mei.MeiXmlReader.java
private MeiElement makeMeiElement(Node element) { // TODO: CDATA // Comments get a name #comment String nshref = element.getNamespaceURI(); String nsprefix = element.getPrefix(); MeiNamespace elns = new MeiNamespace(nshref, nsprefix); MeiElement e = new MeiElement(elns, element.getNodeName()); if (element.getNodeType() == Node.COMMENT_NODE) { e.setValue(element.getNodeValue()); }//from w w w . jav a2s . co m NamedNodeMap attributes = element.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); if (XML_ID_ATTRIBUTE.equals(item.getNodeName())) { e.setId(item.getNodeValue()); } else { String attrns = item.getNamespaceURI(); String attrpre = item.getPrefix(); MeiNamespace atns = new MeiNamespace(attrns, attrpre); MeiAttribute a = new MeiAttribute(atns, item.getNodeName(), item.getNodeValue()); e.addAttribute(a); } } } NodeList childNodes = element.getChildNodes(); MeiElement lastElement = null; for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); if (item.getNodeType() == Node.TEXT_NODE) { if (lastElement == null) { e.setValue(item.getNodeValue()); } else { lastElement.setTail(item.getNodeValue()); } } else { MeiElement child = makeMeiElement(item); e.addChild(child); lastElement = child; } } return e; }
From source file:com.jaspersoft.studio.data.xml.XMLDataAdapterDescriptor.java
private void findDirectChildrenAttributes(Node node, LinkedHashMap<String, JRDesignField> fieldsMap, String prefix) {/*from ww w . j a va2 s .com*/ NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); if (item.getNodeType() == Node.ATTRIBUTE_NODE) { addNewField(item.getNodeName(), fieldsMap, item, prefix); } } } }