BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-04-2007, 10: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, 10: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, 03: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, 02: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





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