Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble with XML parsing  RSS feed

 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Java Geniuses,

I'm having trouble learning how to parse and XML with java. I'm starting with this simple XML file:


And here's the class I wrote to parse it:


And I'm testing it with this class:


This test is failing, saying the size of the ArrayList is 0, so it looks like the attribute values are not getting added to the ArrayList. I think I have some fundamental misunderstanding of how this is supposed to work, can anyone help me out?

Thanks!
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The XML document that you posted doesn't have any attributes, so it is not at all surprising that your code doesn't find any attributes in it. You might want to take a minute to read about XML and find out what an attribute is.
 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, there is my fundamental misunderstanding of what is going on.

Thanks!
 
Campbell Ritchie
Sheriff
Posts: 53742
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this discussion would fit better in our XML forum: moving.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!