The Artima Developer Community
Sponsored Link

Java Answers Forum
re: tearing my hair out!!!

2 replies on 1 page. Most recent reply: Feb 23, 2004 1:04 PM by Mickey

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Mickey

Posts: 7
Nickname: internment
Registered: Feb, 2004

re: tearing my hair out!!! Posted: Feb 23, 2004 12:05 PM
Reply to this message Reply
Advertisement
Hi folks,
I have a parser parsing out CURRENT_TEMP from an XML file at the moment, but when I use the Stringbuffer() method to handle the temperature to pass it into the variable this.currentTemp I don't think it is working. The reason I think this, is that when I do a test on the this.currentTemp variable like so:

if (this.currentTemp == null)
{
System.err.println("currentTemp==null");
systemError();
return;
}

the program prints out currentTemp==null. Anyways, this is the way I have use the Stringbuffer below:



StringBuffer buffer;
String currentTemp;

/**************************************************************************
* The following methods are SAX callback routines. Some of them are empty.
**************************************************************************/
public void setDocumentLocator(Locator locator) { }

/**
* New parsing is started.
*/
public void startDocument() throws SAXException
{
System.out.println("at start of the XML file");
this.currentTemp = null;
}

public void endDocument() throws SAXException
{
System.out.println("at end of the XML file");
}

/**
* Started processing a new element. If the tag is "ROADSURFACE_TEMP",
* prepare a buffer to keep the content.
*/
public void startElement(String name, Attributes atts) throws SAXException
{
if (name.equals("ROADSURFACE_TEMP"))
{
this.buffer = new StringBuffer();
}
}

/**
* An element is just closed. If the element is "CurrTemp",
* copy the content to this.currTemp.
*/
public void endElement(String name) throws SAXException {
if (name.equals("ROADSURFACE_TEMP"))
{
this.currentTemp = this.buffer.toString();
}
}

/**
* Accumulate characters if the buffer has been allocated.
*/
public void characters(char ch[], int start, int length) throws SAXException
{
if (this.buffer != null)
{
//this is just checking if the programs getting this far, which it isn't
System.out.println("hello there");
this.buffer.append(ch, start, length);
System.out.println(this.buffer);
}
}



Any help is very much appreciated.....Thank you in advance!


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: re: tearing my hair out!!! Posted: Feb 23, 2004 12:47 PM
Reply to this message Reply
One thing may be that you say you are parsing for CURRENT_TEMP tag, but you code is looking for ROADSURFACE_TEMP tags

What I frequently do when doing a sax parse is use a temporary String to hold the contents of character data, then set the string corresponding to the tag with the contents of the temporary String when the parser hits the endElement for that tag. If then else logic...

Mickey

Posts: 7
Nickname: internment
Registered: Feb, 2004

Re: re: tearing my hair out!!! Posted: Feb 23, 2004 1:04 PM
Reply to this message Reply
Sorry,
That was a typo, my mistake, I meant ROADSURFACE_TEMP. I'm not sure I fully understand what your saying, am I not already setting up a temporary string in the this.currentTemp variable and passing the value of ROADSURFACE_TEMP into it??

Flat View: This topic has 2 replies on 1 page
Topic: Print a image(bitmap or JPEG) Previous Topic   Next Topic Topic: random acesses from a file

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use