This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Trouble with XML parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Trouble with XML parsing" Watch "Trouble with XML parsing" New topic
Author

Trouble with XML parsing

Matthew Busse
Ranch Hand

Joined: Sep 29, 2010
Posts: 52
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

Joined: Oct 14, 2005
Posts: 19723
    
  10

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

Joined: Sep 29, 2010
Posts: 52
Ah, there is my fundamental misunderstanding of what is going on.

Thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43933
    
  33
I think this discussion would fit better in our XML forum: moving.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Trouble with XML parsing
 
It's not a secret anymore!