Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default Please please help!!

    All,
    I had posted before on the same topic but did not get much help, I am so blocked and really need help from you.

    I need to read the XML file having following data and need to store in the hashmap. Could you plz plz help me to get this right?? How do I read multiple attributes with multiple elements?

    <ip address="88.131.106.22" consecutive_listings="2" listing_ratio="2" reputation="8">
    <attacks hostility="3" confidence="4" />
    <bot confidence="4" />
    </ip

    So far I have come up with following function to read one element with one attribute but not able to come up anything beyond that.

    public String getElementAttribute(String elementName, String attribute){
    NodeList nodeList = doc.getElementsByTagName(elementName);
    String res = "";
    int len = nodeList.getLength();

    if (nodeList.getLength() == 1) {

    NamedNodeMap nMap= nodeList.item(0).getAttributes();
    res = nMap.getNamedItem(attribute).getNodeValue();
    }
    else {
    logger.error("Element List Length is [" + len + "] for [" + elementName + "]");
    }

    return res;
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default

    Could you post code that will compile and execute?
    Also show what the program generates and show what you would like it to generate.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •