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!

Recommended Answers

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

Jump to Post

All 2 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.