xml trouble

N

Nik

I have my xml file which looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
- <enatureArchiver>
- <archive name="music">
- <disc name="mp3">
- <file name="Audioplacid - Heaven 0.9.1.mp3">
<size>11911528</size>
<subpath>D:\Mp3</subpath>
<ext>mp3</ext>
<added>1112185739331</added>
<disc>mp3</disc>
<comment />
<rating />
<hidden />
</file>
- <file name="Audioplacid - Heaven 0.9.mp3">
<size>11974128</size>
<subpath>D:\Mp3</subpath>
<ext>mp3</ext>
<added>1111497873734</added>
<disc>mp3</disc>
<comment />
<rating />
<hidden />
</file>
....


what I wanna do now is to read:
- all the "file" attributes
- only the ones within the "archive" tag with the attribute "music"
- only the ones within the "disc" tag with the attribute "mp3"
(there are different attributes of the disc and archive tag)

unfortunately I could not make this to work. I could not find out how I
can go deeper down in the tree.
here is the code I have so far:

<JAVA>
xmldoc = BasicDom.parseXmlFile(XMLFILE,false);

// Get a list of all elements in the document
NodeList list = xmldoc.getElementsByTagName("*");
for (int i=0; i<list.getLength(); i++) {

// Get element
Element element = (Element)list.item(i);
if(element.getTagName().equals("archive"))
{
System.out.print(element.getAttribute("name"));

}

}

</JAVA>

thanks in advance for any help or advise.
 
R

Ross Bamford

I have my xml file which looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
- <enatureArchiver>
- <archive name="music">
- <disc name="mp3">
- <file name="Audioplacid - Heaven 0.9.1.mp3">
<size>11911528</size>
<subpath>D:\Mp3</subpath>
<ext>mp3</ext>
<added>1112185739331</added>
<disc>mp3</disc>
<comment />
<rating />
<hidden />
</file>
- <file name="Audioplacid - Heaven 0.9.mp3">
<size>11974128</size>
<subpath>D:\Mp3</subpath>
<ext>mp3</ext>
<added>1111497873734</added>
<disc>mp3</disc>
<comment />
<rating />
<hidden />
</file>
...


what I wanna do now is to read:
- all the "file" attributes
- only the ones within the "archive" tag with the attribute "music"
- only the ones within the "disc" tag with the attribute "mp3"
(there are different attributes of the disc and archive tag)

unfortunately I could not make this to work. I could not find out how I
can go deeper down in the tree.
here is the code I have so far:

<JAVA>
xmldoc = BasicDom.parseXmlFile(XMLFILE,false);

// Get a list of all elements in the document
NodeList list = xmldoc.getElementsByTagName("*");
for (int i=0; i<list.getLength(); i++) {

// Get element
Element element = (Element)list.item(i);
if(element.getTagName().equals("archive"))
{
System.out.print(element.getAttribute("name"));

}

}

</JAVA>

thanks in advance for any help or advise.

http://jakarta.apache.org/commons/digester/

Ross
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top