I am looking for a way to read an XML file to a hashmap.
So far I have learned to use javax.xml.parsers.*; tools to read the XML file
and I can send different elements of the XML file to the screen all day.
here is some snippets of what I'm doing now:
---------------------------
public class GLDefaultLoader {
protected String xmlFileName = "gl.xml";
private Document loadXML(String filename) throws Exception {
filename= "gl.xml";
Document doc = null;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new com.abcsinc.fwk.dom.MySaxErrorHandler());
doc = db.parse(new File("gl.xml").getAbsolutePath());
} // after this we do variuos catches
// here Im getting started on my hashmap
private HashMap buildGLDefaultsItems(Document doc) throws IOException,
ParserConfigurationException,
SAXException {
HashMap hashMap = new HashMap();
doc.getDocumentElement().normalize();
System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName());
NodeList listOfQueries = doc.getElementsByTagName("glDefaultsItem");
int totalQueries = listOfQueries.getLength();
System.out.println("Total number of Queries : " + totalQueries);
----------------------------------------
I think I'm going In the right direction but I'm kinda stuck, wallowing in ignorance maybe, lol