File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Reading XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Reading XML" Watch "Reading XML" New topic
Author

Reading XML

James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
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

Joined: Mar 22, 2000
Posts: 12675
    
    5
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.


Java Resources at www.wbrogden.com
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

William Brogden wrote:
Bill
Note that we have an XML forum where this really belongs.


XML and Related Technologies forum we go.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 14, 2009
Posts: 82
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 22, 2000
Posts: 12675
    
    5
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 14, 2009
Posts: 82
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading XML
 
Similar Threads
ArrayList Problem while parsing XML...
I do not know in which part of SAX Class
Can any one help me
My StartElement method doesn�t work
complex XML doct & SAX parsing