Results 1 to 6 of 6
  1. #1
    krishkill is offline Member
    Join Date
    May 2010
    Posts
    11
    Rep Power
    0

    Default parsing XML in JAVA

    I have a huge XML file, and my task is to extract desired data from the file. Like in the file attached which is a small part of big xml file i have. The root element is PMI_StandardMonthly_Rate. And then depending on users input sheetname i need to select MITable(there are a couple I pasted only one in the file attached),then depending on MIPremiumPaymentType entered I need to select one table..
    finally the user will enter into one of the LTV tables depending on his inputs. Once he enters the coverage in MIRate, I need to display inital and renewal rates. Please help me how i need to proceed and model code selecting tables depending on attributes.

    Thanks in advance.

    CODE
    ----------------------------------------------------------------

    <?xml version="1.0" encoding="UTF-8" ?>
    - <PMI_StandardMonthly_Rate Disclosure="The rate quote generated is only an estimate based on the information you provided. It does not constitute a contract.">
    - <MITables EffDate="2008-09-02" SheetName="PMI_STANDARD_MONTHLY">
    - <MIPremiumPaymentType MIPremiumPaymentType="BorrowerPaid">
    - <PaymentType PaymentType="ARM">
    - <AmortTerm AmortTermGt="60" AmortTermMax="480">
    - <CreditScore CreditScoreGt="580" CreditScoreMax="599">
    - <PaymentPlan PaymentPlan="Level Annual">
    - <RefundType RefundType="Refundable">
    - <RenewalType RenewalType="Declining">
    - <LTV LTVgt="0.00" LTVmax="85.00">
    <MIRate Coverage="35" IntialRate="0.03100" RenewalRate1="0.03100" />
    <MIRate Coverage="33" IntialRate="0.02940" RenewalRate1="0.02940" />
    <MIRate Coverage="30" IntialRate="0.02700" RenewalRate1="0.02700" />
    <MIRate Coverage="25" IntialRate="0.02310" RenewalRate1="0.02310" />
    <MIRate Coverage="22" IntialRate="0.02050" RenewalRate1="0.02050" />
    <MIRate Coverage="20" IntialRate="0.01880" RenewalRate1="0.01880" />
    <MIRate Coverage="18" IntialRate="0.01710" RenewalRate1="0.01710" />
    <MIRate Coverage="17" IntialRate="0.01610" RenewalRate1="0.01610" />
    <MIRate Coverage="15" IntialRate="0.01440" RenewalRate1="0.01440" />
    <MIRate Coverage="14" IntialRate="0.01350" RenewalRate1="0.01350" />
    <MIRate Coverage="12" IntialRate="0.01170" RenewalRate1="0.01170" />
    <MIRate Coverage="10" IntialRate="0.01000" RenewalRate1="0.01000" />
    <MIRate Coverage="6" IntialRate="0.00800" RenewalRate1="0.00800" />
    <MIRate Coverage="4" IntialRate="0.00730" RenewalRate1="0.00730" />
    </LTV>
    - <LTV LTVgt="85.01" LTVmax="90.00">
    <MIRate Coverage="35" IntialRate="0.04060" RenewalRate1="0.04060" />
    <MIRate Coverage="33" IntialRate="0.03860" RenewalRate1="0.03860" />
    <MIRate Coverage="32" IntialRate="0.03760" RenewalRate1="0.03760" />
    <MIRate Coverage="30" IntialRate="0.03550" RenewalRate1="0.03550" />
    <MIRate Coverage="28" IntialRate="0.03350" RenewalRate1="0.03350" />
    <MIRate Coverage="27" IntialRate="0.03240" RenewalRate1="0.03240" />
    <MIRate Coverage="25" IntialRate="0.03010" RenewalRate1="0.03010" />
    <MIRate Coverage="22" IntialRate="0.02660" RenewalRate1="0.02660" />
    <MIRate Coverage="20" IntialRate="0.02430" RenewalRate1="0.02430" />
    <MIRate Coverage="18" IntialRate="0.02200" RenewalRate1="0.02200" />
    <MIRate Coverage="17" IntialRate="0.02090" RenewalRate1="0.02090" />
    <MIRate Coverage="16" IntialRate="0.01970" RenewalRate1="0.01970" />
    <MIRate Coverage="14" IntialRate="0.01740" RenewalRate1="0.01740" />
    <MIRate Coverage="12" IntialRate="0.01510" RenewalRate1="0.01510" />
    <MIRate Coverage="10" IntialRate="0.01280" RenewalRate1="0.01280" />
    <MIRate Coverage="8" IntialRate="0.01050" RenewalRate1="0.01050" />
    <MIRate Coverage="6" IntialRate="0.00910" RenewalRate1="0.00910" />
    </LTV>

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by krishkill View Post
    I have a huge XML file, and my task is to extract desired data from the file.
    If your XML file is huge then normally the resulting DOM is huge so I'd go for the SAXParser approach and pass it your own DefaultHandler. The handler is called when the parser 'sees' nodes or the end of them etc. It's up to your handler to, well, handle them. Read the API documentation for the DefaultHandler class; you have to extend it and grab the data when the parser passes it to your handler.

    kind regards,

    Jos

  3. #3
    krishkill is offline Member
    Join Date
    May 2010
    Posts
    11
    Rep Power
    0

    Default

    I'm doing somethin like dis..


    public class SAXparserExample extends DefaultHandler {


    try {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    sp.parse("C:/Users/Krishkill/IBM/rationalsdp/workspace/Learning/PMI.xml", this);
    }catch(Exception ex){

    }

    once it do parsing how do i need to check for tables,
    even wen i tried using DOM i hav a command

    NodeList listOfTables = doc.getElementsByTagName("MITables");

    but i want a specific table in MITables with sheet name="PMI_Standard _Monthly". How to specify that attribute.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    The SAX parser calls your handler when it parses the text. There is no DOM, you have to grab your data on the fly; read the DefaultHandler class documentation and extend the methods you need. You can't just hope that some magic will happen.

    kind regards,

    Jos

  5. #5
    krishkill is offline Member
    Join Date
    May 2010
    Posts
    11
    Rep Power
    0

    Default

    Thanx Jos, I will go thru defaulthandler nd figure it out.. thnx a lot..

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Another option that I've heard good things about is the StAX parser also now part of core Java. I've not yet tried it as all of my XML has been small enough to do with DOM.

    Much luck!

Similar Threads

  1. Parsing Problem in Java
    By vidya in forum Advanced Java
    Replies: 4
    Last Post: 02-01-2010, 03:48 PM
  2. Parsing Problem in Java
    By vidya in forum New To Java
    Replies: 2
    Last Post: 02-01-2010, 01:52 PM
  3. Replies: 1
    Last Post: 05-31-2009, 06:48 PM
  4. need very basic help with xml parsing in java
    By 2potatocakes in forum New To Java
    Replies: 7
    Last Post: 09-17-2008, 12:22 PM
  5. Parsing URL in Java
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:14 PM

Posting Permissions

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