Forum Stats

  • 3,874,070 Users
  • 2,266,673 Discussions
  • 7,911,721 Comments

Discussions

What am I missing here?

843834
843834 Member Posts: 49,972
edited Jun 18, 2001 9:27PM in Java Technology & XML
Take a look at this code, I'm trying to extract the value of the tag<question_text>Some question</question_text> from my xml document, I get the question text, but everthing else along with it.


public void startElement (String uri, String name,
String qName, Attributes atts)
{

if( name.equals("question_text")){

question_text = true;

}// close if
}//close start element

public void characters (char ch[], int start, int length)
{


if(question_text){
String question = new String(ch).substring(start,start + length);
System.out.println( question );
}// close if
}//close characters

Can't seem to isolate just the question_text
TIA
Jim

Comments

  • 843834
    843834 Member Posts: 49,972
    Instead of this:
    question = new String(ch).substring(start,start +
    length);

    Try:
    question = new String(ch, start,length);




    >
    public void characters (char ch[], int start, int
    length)

    {





    if(question_text){

    String question = new
    uestion = new String(ch).substring(start,start +
    length);

    System.out.println( question );

    }// close if

    }//close characters



    Can't seem to isolate just the question_text

    TIA

    Jim
  • 843834
    843834 Member Posts: 49,972
    Hi,
    Actually the answer was in the endElement,
    question_text = false;

    therefore turning off the listener for question text before it was staying true for everything.

    Thanks for the reply, and I'll try your suggestion also
    Jim
This discussion has been closed.