Need help - extract node using JAVA Xpath

Discussion in 'Java' started by brahatha, Jun 5, 2007.

  1. brahatha

    brahatha Guest

    I am trying to come up with a Java code where I can read a xml file
    and extract particular element/attribute. This is the structure of
    xml
    I have

    <RootElement>
    <colAttempt>
    <Attempt a="1" b="abc>
    <ResultElement Result = "123" Msg="success">
    <nodeList>
    <NodeIwant nodeName="conf" noFail="1">
    <Data ProgId="294"/>
    </NodeIwant>
    <NodeIwant nodeName="nconf" noFail="0">
    <Data ProgId="3"/>
    </NodeIwant>
    </nodeList>
    </ResultElement>


    </Attempt>
    <Attempt c="2" d="abc>
    <ResultElement Result = "123" Msg="success">
    <nodeList>
    <NodeIwant nodeName="xyz" noFail="0">
    <Data ProgId="4"/>
    </NodeIwant>
    </nodeList>
    </ResultElement>


    </Attempt>


    </colAttempt>
    </RootElement>


    I need to extract <NodeIwant nodeName="" noFail =""> for each
    iteration of Attempt.In the above example, I have two Attempts ( 1
    and
    2 ). So my output should show, for attempt 1 following result
    <NodeIwant nodeName="conf" noFail="1">
    <NodeIwant nodeName="nconf" noFail="0">


    For attempt 2 following
    <NodeIwant nodeName="xyz" noFail="0">


    So final result should be like this,


    Attempt 1:
    <NodeIwant nodeName="conf" noFail="1">
    <NodeIwant nodeName="nconf" noFail="0">
    Attempt 2:
    <NodeIwant nodeName="xyz" noFail="0">


    NEED HELP!
     
    brahatha, Jun 5, 2007
    #1
    1. Advertising

  2. brahatha

    brahatha Guest

    On Jun 5, 1:04 pm, brahatha <> wrote:
    > I am trying to come up with a Java code where I can read a xml file
    > and extract particular element/attribute. This is the structure of
    > xml
    > I have
    >
    > <RootElement>
    > <colAttempt>
    > <Attempt a="1" b="abc>
    > <ResultElement Result = "123" Msg="success">
    > <nodeList>
    > <NodeIwant nodeName="conf" noFail="1">
    > <Data ProgId="294"/>
    > </NodeIwant>
    > <NodeIwant nodeName="nconf" noFail="0">
    > <Data ProgId="3"/>
    > </NodeIwant>
    > </nodeList>
    > </ResultElement>
    >
    > </Attempt>
    > <Attempt c="2" d="abc>
    > <ResultElement Result = "123" Msg="success">
    > <nodeList>
    > <NodeIwant nodeName="xyz" noFail="0">
    > <Data ProgId="4"/>
    > </NodeIwant>
    > </nodeList>
    > </ResultElement>
    >
    > </Attempt>
    >
    > </colAttempt>
    > </RootElement>
    >
    > I need to extract <NodeIwant nodeName="" noFail =""> for each
    > iteration of Attempt.In the above example, I have two Attempts ( 1
    > and
    > 2 ). So my output should show, for attempt 1 following result
    > <NodeIwant nodeName="conf" noFail="1">
    > <NodeIwant nodeName="nconf" noFail="0">
    >
    > For attempt 2 following
    > <NodeIwant nodeName="xyz" noFail="0">
    >
    > So final result should be like this,
    >
    > Attempt 1:
    > <NodeIwant nodeName="conf" noFail="1">
    > <NodeIwant nodeName="nconf" noFail="0">
    > Attempt 2:
    > <NodeIwant nodeName="xyz" noFail="0">
    >
    > NEED HELP!


    I tried this as suggested by Martin Honnen,
    /RootElement/colAttempt/*[starts-with(name(),'Attempt')]/
    ResultElement/nodeList/NodeIwant
    I get NPE.
     
    brahatha, Jun 5, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,470
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,417
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,440
    Dimitre Novatchev
    Aug 24, 2006
  4. brahatha
    Replies:
    1
    Views:
    683
    Martin Honnen
    Jun 5, 2007
  5. njsimha
    Replies:
    0
    Views:
    785
    njsimha
    Sep 16, 2008
Loading...

Share This Page