Results 1 to 3 of 3
  1. #1
    victor_sk is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default Parsing XML question

    Hi everyone,

    I am using a Node class from org.w3c.dom package and I have an XML in the following format:

    <BasicPropertyInfo ChainCode="XX" HotelCode="1234567" HotelCityCode="FSG" HotelName="TEST HOTEL" AreaID="65NE">

    I know how to obtain elements by calling child and sibling elements of a Node but I don't know how to extract values in that format.

    For example, which methods am I to call to extract value for ChainCode or HotelCode? They are inside the BasicPropertyInfo element but I can't resolve whether ChainCode is a child or a sibling node. Could somebody point me in the right direction please?

    Thanks,
    Victor.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    ChainCode and the others are attributes! So if you have the right BasicPropertyInfo element you can call something like

    Java Code:
    getAttributes().getNamedItem("ChainCode").getNodeValue()
    Or select all ChainCodes with XPath, e.g.:
    Java Code:
    		XPathFactory xfactory = XPathFactory.newInstance();
    		XPath path = xfactory.newXPath();
    		XPathExpression exp = path.compile("//BasicPropertyInfo/@ChainCode"); 
    		NodeList nodes = (NodeList) exp.evaluate(doc, XPathConstants.NODESET);
    		for (int i = 0; i < nodes.getLength(); i++) {
    		    System.out.println(nodes.item(i).getNodeValue()); 
    		}
    :confused:

  3. #3
    victor_sk is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    Hi,

    Thank you so much for this information. They trick is in NamedNodeMap .

    Thank you :)

Similar Threads

  1. help with parsing
    By ace_03 in forum New To Java
    Replies: 15
    Last Post: 11-24-2009, 09:02 PM
  2. Parsing XML
    By virvalid in forum Advanced Java
    Replies: 3
    Last Post: 08-10-2009, 12:40 PM
  3. Parsing
    By Matt Sakko in forum New To Java
    Replies: 14
    Last Post: 03-21-2009, 04:49 PM
  4. Xml Parsing
    By Nomad in forum XML
    Replies: 12
    Last Post: 02-22-2009, 11:19 AM
  5. xml parsing
    By gaurav65176 in forum XML
    Replies: 5
    Last Post: 11-12-2008, 11:07 AM

Posting Permissions

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