0

Hi guys

I have a tricky XML/Java situation that I need some tips on
I have an XML file
<country>
<country-name code=”USA”>
<city>City1</city>
<city>City2</city>
<city>City3</city>
</country-name>

<country-name code=”FRA”>
<city>City1</city>
<city>City2</city>
<city>City3</city>
</country-name>

</country >

Firstly I need to count how many cities per country. I know I have to get the parent and child nodes and so on
Secondly I need to display these cities names per country (if code =”FRA”)'

How do I do this in Java?
Thanks in advance!

3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by orko
0

Hi michael.ngobeni,

Have a read of the javax.xml classes in the Java API. You should look in particular at the parsers package. Another step might be the java xml tutorials on sun.com.

Anyway I hope this has given you a starting point. Post back if you need more help.

Cheers
darkagn

0

yah... java's xml parsers can help you more... couple of them r, DOM, JDOM, SAX...
if u use DOM or JDOM, get the whole document parsed, then just use a method called getElementsByTagName(String Tag). This is pretty easy to do. you will have to follow factory pattern.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.