Results 1 to 5 of 5
  1. #1
    Jack is offline Senior Member
    Join Date
    Jun 2007
    Posts
    130
    Rep Power
    0

    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.
    Java 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

  2. #2
    Peter is offline Senior Member
    Join Date
    Jun 2007
    Posts
    119
    Rep Power
    0

    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.

  3. #3
    Ed
    Ed is offline Senior Member
    Join Date
    Jun 2007
    Posts
    110
    Rep Power
    0

    Default

    Check xstream to do java to xml and xml to java. Very easy to use XStream - Two Minute Tutorial

  4. #4
    zerocool333 is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Default Hi

    Hi guys,
    Its my first post to say HI to all of you.

  5. #5
    jason_check is offline Member
    Join Date
    Feb 2009
    Posts
    10
    Rep Power
    0

    Default

    JDom is also a good choice.
    View, validate and edit X9.37, X9.100-180 and UCD ICL files.
    http://www.digertech.com

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •