• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading XML

 
James Howerton
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name of this question is Reading xml
Hello and Thank you in advance for any assistance.


System info:Netbeans

netbeans,glassfish,MySQL

The Purpose of this post is:

learn how to read XML into program.


The functionality of this code is:

To use the stack.push() to put XML elements in it and output XML elements System.out.println

My question is:

I do not understand stack.push(). It says it found the zooinventory.xml but the SAXModelBuider.java is not putting them on the stack.

The errors related to this code are:



Code description:

TestModelBuilder.java (main())



Code description

SAXModelBuilder.java (push elements to the stack)


Thanks again.
-ceyesumma

Note:
………………………………………………………………………………………………

Code description


 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a mess -
for example, in the loop at line 39 you

repeatedly push the same element, once for each attribute.

In line 46 and 58 you pop the stack without checking to see if it is empty.

If this is your first SAX program I suggest you start with something simpler.

For example, just doing a System.out.println in each of the event methods to verify that the events contain what you expect.

Bill
Note that we have an XML forum where this really belongs.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:
Bill
Note that we have an XML forum where this really belongs.


XML and Related Technologies forum we go.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code is pretty difficult to understand... that setProperty method is impossible.

For example, if the method starts with "add", what ever happens? As far as I can tell, nothing.
 
James Howerton
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize. I did not see the XML forum.

The program is an example from a book. I thought the class was responsible for putting elements from the XML on the stack. It has several more classes. I was under the impression that it works sense everything compiled. I was trying to find out if it would run but it starts by saying nothing is on the stack. I will continue working with it to see if I can figure out how it works.
I'll look for the XML forum I did not see it.

Thanks
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the one that starts with "XML"--the post has already been moved.

Let this be a reminder--just because something compiles doesn't mean it does what we want!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program is an example from a book.


If that is indeed a direct quote from the book, you should demand your money back. Not only does it have the errors various ranchers have pointed out, it is needlessly complicated for capture of SAX event data.

Bill
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://onjava.com/pub/a/onjava/excerpt/learnjava_23/index2.html?page=2

It's from the 2002 Learning Java O'Reilly book.
 
James Howerton
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never figured out why the stack().push did work thanks though.

I just re wrote it to push elements into the array. works good enough for now. Thanks for all your time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic