|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
re: Tearing my hair out!!!
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! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > re: Tearing my hair out!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|