Javaサンプル XMLタグ・属性表示
import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Attr; import org.xml.sax.SAXException; class XMLsample { public static void main(String[] args) throws Exception { String filename, tagname, attrname; XMLReader reader; filename = args[0]; tagname = args[1]; attrname = ""; if(args.length == 3) { attrname = args[2]; } reader = new XMLReader(filename); reader.getNodeValue(tagname, attrname); System.exit(0); } } class XMLReader { private Element rootElement; XMLReader(String filename) throws IOException, SAXException, ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = factory.newD...