Java tutorial
//package com.java2s; /*** Java Commons and Niceties Library from CrunchyNoodles.com *** Copyright (C) 2014 in USA by Brian Witt , bwitt@value.net *** *** Licensed under the Apache License, Version 2.0 ( the "License" ) ; *** you may not use this file except in compliance with the License. *** You may obtain a copy of the License at: *** http://www.apache.org/licenses/LICENSE-2.0 *** *** Unless required by applicable law or agreed to in writing, software *** distributed under the License is distributed on an "AS IS" BASIS, *** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *** See the License for the specific languatge governing permissions and *** limitations under the License. ***/ import java.io.PrintStream; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /*** * Print every attribute and value of a node, one line at a time. * If {@link entry} is null, then outputs "<null/>". * * @param outs where to send output, cannot be null. * @param entry XML node to examine, OK if null. */ public static void XmlPrintAttrs(PrintStream outs, Node entry) { if (entry == null) { outs.print("<null/>"); return; } // see http://www.w3.org/2003/01/dom2-javadoc/org/w3c/dom/NamedNodeMap.html NamedNodeMap attrs = entry.getAttributes(); for (int k = attrs.getLength(); --k >= 0;) { Node n = attrs.item(k); outs.printf("+++ has attr %s = %s\n", n.getNodeName(), n.getNodeValue()); } } }