Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sending an XML file to a hashmap, using one of the elements as a key?

843834Apr 20 2005 — edited Apr 25 2005
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 23 2005
Added on Apr 20 2005
1 comment
194 views