Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2007, 10:15 AM
Senior Member
 
Join Date: Jun 2007
Posts: 130
Rep Power: 0
Jack is on a distinguished road
Default Parse XMLfile as String using SAX parser
Hi
I am trying to use SAX parser.

Here is the requirement
I will get the XML file as string from a third party application. Now I need to get the java objects out of this String by using SAX parser.

Sample XML string as below.
Code:
String xmlString="<?xml version="1.0" encoding="UTF-8"?><response><record><Id>04334</Id>
<Type>A</Type><effectiveDate /><lastModifiedDate>2006-04-03 00:00:00</lastModifiedDate>
<modifiedBy>GH002</modifiedBy>
<associatedSisId /><risk><namedInsured> <firstName>Barney</firstName><lastName>Rubble
</lastName>
</namedInsured><address><street1>123 Easy Street</street1>
<street2>Apartment 5</street2><city>Madras</city> <state>TN</state><zip5>55345340</zip5>
 <zip4>2333</zip4></address></risk></record>"
I need parse this using SAX and get the values out of it.
thanks
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-04-2007, 10:17 AM
Senior Member
 
Join Date: Jun 2007
Posts: 119
Rep Power: 0
Peter is on a distinguished road
Default
SAX is not a good choice for your requirement. A better idea would be to use DOM if the String that you recieve contains more then 1 records.
However if you insist on using SAX
In brief, you will have to override the existing functions in the DefaultHandler like startelement(), characters() etc and you will have to populate your Record Object by the Values that the parser returns.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-04-2007, 10:17 AM
Ed Ed is offline
Senior Member
 
Join Date: Jun 2007
Posts: 110
Rep Power: 0
Ed is on a distinguished road
Default
Check xstream to do java to xml and xml to java. Very easy to use XStream - Two Minute Tutorial
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-20-2009, 08:52 AM
Member
 
Join Date: Feb 2009
Posts: 1
Rep Power: 0
zerocool333 is on a distinguished road
Default Hi
Hi guys,
Its my first post to say HI to all of you.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-22-2009, 05:31 PM
Member
 
Join Date: Feb 2009
Posts: 10
Rep Power: 0
jason_check is on a distinguished road
Default
JDom is also a good choice.
__________________
View, validate and edit X9.37, X9.100-180 and UCD ICL files.
http://www.digertech.com
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Parse int to a string variable raj reddy Java Servlet 10 01-09-2009 08:41 PM
how to Parse int to a string variable (pls hlp) raj reddy Threads and Synchronization 5 06-10-2008 07:32 AM
How to parse String effectively based on a dilimiter raghu408 Advanced Java 26 04-10-2008 11:55 PM
SAX Parse bluefloyd8 New To Java 1 01-25-2008 04:57 PM
How to parse in html paty New To Java 1 07-24-2007 01:29 AM


All times are GMT +2. The time now is 06:45 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org