BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 09-04-2007, 09:51 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: May 2006
Location: Virginia
Model: 8700
Carrier: Verizon
Posts: 25
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting data into xml

Please Login to Remove!

I have an application that receives an xml data form. The aplpication is then suppose to insert data into that xml form and send it back out. I'm having trouble inserting data into the xml form, can anyone help with code snippets??
Offline  
Old 09-04-2007, 09:59 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: t-mobile
Posts: 44
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You will need a SAXParser and a ResponseHandler for taking the necessary actions.
Code:
	public XMLParser(StringBuffer raw){
		try{
			handler = new ResponseHandler();
			factory = SAXParserFactory.newInstance();
			saxParser = factory.newSAXParser();
			in = new ByteArrayInputStream(raw.toString().getBytes());
			inputSource = new InputSource(in);
		}catch(Exception e){e.printStackTrace();}		
	}

	public void run(){
		try {
			saxParser.parse(inputSource, handler);			
		} catch (SAXException e) {e.printStackTrace();
		} catch (IOException e) {e.printStackTrace();}
	}

private class ResponseHandler extends DefaultHandler{
		
		public void startDocument ()throws SAXException{
		}
		
		public void startElement(String uri, String localName, String qName, Attributes attributes)throws SAXException{	
		}
		
		public void endElement(String uri, String localName, String qName)throws SAXException{
		}
		
		public void endDocument()throws SAXException{
		}		
	}
where the InputSource is your XML-File stored in a StringBuffer.
Offline  
Old 09-04-2007, 02:03 PM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: May 2006
Location: Virginia
Model: 8700
Carrier: Verizon
Posts: 25
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

With your StartElement, are you referring to using the JDE's Element? In that case, how do you inistialize an Element as well as set the name of the Element(node)? Is that SetPrefix()??
Offline  
Old 09-05-2007, 01:29 AM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: t-mobile
Posts: 44
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

With Element a XML-Element is meant, DefaultHandler is an Interface provided by the SAXParser, which when used must implement the four methods you see above. Within this methods you can determine, how the SAXParser should interact with your application when the actions (startDocument, endDocument, startElement, endElement) take place.

I would suggest that you take a look at some documentation or a book on SAXParsing, you should be able to get a basic understanding in a very short time.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Tektronix TM503 Power Mainframe/ 3-Slot Chassis Fully Tested w/ 30 days warranty
$120.0
Tektronix TM503 Power Mainframe/ 3-Slot Chassis Fully Tested w/ 30 days warranty pictureLINK SYSTEMS MDI BD SPECTRA 3 AQND 4 ADC DISC BD GP BOA 7 SLOT MAINFRAME X
$179.99
LINK SYSTEMS MDI BD SPECTRA 3 AQND 4 ADC DISC BD GP BOA 7 SLOT MAINFRAME  X pictureAgilent HP 35650A System Mainframe w/Three 35655A's
$45.0
Agilent HP 35650A System Mainframe w/Three 35655A's pictureAgilent 66000A MPS Mainframe w/ 8 Power Modules(66102A,66101A,66103A), Working
$1150.0
Agilent 66000A MPS Mainframe w/ 8 Power Modules(66102A,66101A,66103A), Working pictureNewport 1830C Power Meter Mainframe and 818-IG Detector with Calibration Module
$1685.0
Newport 1830C Power Meter Mainframe and 818-IG Detector with Calibration Module picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.