Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2007, 10:15 AM
Senior Member
 
Join Date: Jun 2007
Posts: 130
Jack is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 07-04-2007, 10:17 AM
Senior Member
 
Join Date: Jun 2007
Posts: 119
Peter is on a distinguished road
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
Ed is on a distinguished road
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
Sponsored Links
Reply


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

vB 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 4 06-27-2008 12:58 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 +3. The time now is 12:56 AM.


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