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 I tried find the BUG in this SAX PARSER But NO-RESULT: 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 "I tried find the BUG in this SAX PARSER But NO-RESULT:" Watch "I tried find the BUG in this SAX PARSER But NO-RESULT:" New topic
Author

I tried find the BUG in this SAX PARSER But NO-RESULT:

Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
I tried find the BUG in this SAX PARSER But NO-RESULT:

line 102: output("\nName:" + searchname +.... //searchname goes to output SUCCESS (endDocument())
......................................
line 149: if (getRest==1 && state == 2) // endElement()
line 150: searchname=str; // this [u]does not go[/u] to line 102

Can you help?

what files allowed to attach, you can find sax.zip at http://www.poliscarhire.com/js/sax.zip [2KB]
contains java and xml files...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
What language are those code fragments in?

What do those fragments have to do with a SAX parser?

Bill
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
java, see code in zip in url....
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

You don't expect us to download and unzip that file, do you really? If you have a question about some code, then post it here. And if that code is very long, just post the relevant parts of it.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
I have review file for 45min and also Netbeans does not highlight errors in code, is about 170 lines with comments, and I think is the only way find the bug...

otherwise see below:

[code] public void endDocument( ) throws SAXException {
try {
// Write newline character and then flush the output
newLine( );
writer.flush( );
// Display total number of plant tags encountered
output("Total number of different plants was: "
+ j);
//output("\nMinimum on hand balance is: " + min + " for plant " + minPlant);
output("\nName:" + searchname +
"\nOnHand:" + searchonHand +
"\nSci Name:" +searchscientificName+
"\ncolor:" + searchcolor); //searchonHand

} catch (IOException e) {
throw new SAXException("I/O error", e);
}
} // end of method endDocument
[/code]

[code] public void endElement(String namespaceURI,
String sName, String qName) throws SAXException {



if (state == 2 && searchname.equals(str))
getRest=1;

if (state == 2 && !searchname.equals(str))
getRest=0;

if (getRest==1 && state == 1) // here error does not go to endDocument( )
searchonHand=str; // if put eg str="ccc" does not go , so error on the way towards: line 102 endDocument( )

if (getRest==1 && state == 2)
searchname=str;

if (getRest==1 && state == 3)
searchscientificName=str;

if (getRest==1 && state == 4)
searchcolor=str;

} // end of method endElement [/code]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Please try to concisely state what you expected your program to do and what it actually does.

These code fragments are not helping.

I recommend Harold's free online XML and Java tutorial. At least read the SAX chapter.

Bill
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
run as
java FindPlant nameofplan
eg. nameofplan=Violet
to get below info for this nameofplan along with other data ...problem: does not get the below data?
Name:
OnHand:
Sci Name:
color:
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Where in the program is the String from the command line used?

Showing a sketch of the endDocument event handler has nothing whatsoever to do with solving the problem.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403


[code]
.......................
static public String searchname = " ";
static public String searchscientificName = " ";
static public String searchonHand = " ";
static public String searchcolor = " ";
.......................
if (args.length !=1)
{
System.out.print("enter a plant name");
System.exit(1);
} else
searchname = args[0];
.......................
[/code]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
You know what?

I give up - I have helped teach a lot of people Java but usually they made an effort to listen to what I wrote.

Good luck!
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
Netbeans does not highlight errors in code and I found no bug but stills do NOT give me the 4 values, well I know elementary Java , some Adv concepts, JSP/Servlets also get diploma(x3) from javaonline.org on java/adv java/jsp....
 
 
subject: I tried find the BUG in this SAX PARSER But NO-RESULT: