This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes XML and Related Technologies and the fly likes Retrieve data from childs in XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Retrieve data from childs in XML" Watch "Retrieve data from childs in XML" New topic
Author

Retrieve data from childs in XML

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 336
i

In order to access to this data in my .xml

<company>
<dimension>
<CityName>Boston</CityName>
<browser>Explorer</browser>
</dimension>
</company>


I use the method:



company = companyData.item(0);
if (company.getNodeType() == Node.ELEMENT_NODE) {

Element elemento = (Element) company;
String com = getTagValue("name", elemento);
if (com.equals(companyName)) {

this.setDimension(getTagValue("dimension", elemento));


}



// Return nodo with data
return company;

}

public String getTagValue(String tag, Element elemento) {

NodeList lista = elemento.getElementsByTagName(tag).item(0)
.getChildNodes();

Node valor = (Node) lista.item(0);

return valor.getNodeValue();

}


I need retrieve values store in the tags "CityName" and "browser". What way could I get them?

Many Thanks,

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieve data from childs in XML