substituting variable for an attribute

B

brahatha

I have the following xml

<RootElement>
<colAttempt>
<Attempt attemptid="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 attemptid="2" d="abc>
<ResultElement Result = "123" Msg="success">
<nodeList>
<NodeIwant nodeName="xyz" noFail="0">
<Data ProgId="4"/>
</NodeIwant>
</nodeList>
</ResultElement>
</Attempt>
</colAttempt>
</RootElement>


I am trying to get my final result as follows.

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


So far in my code, I have extracted no of Attempts which is 2 and
looping through that. Now what I am trying to do is to get no of
NodeIwant, so that I can loop through that. So for each Attempt, I
need to get no of NodeIwant and then print the result.

so my xpath is this, /RootElement/colAttempt/Attempt[@attemptid =
$AttrValue]/ResultElement/
nodeList/NodeIwant

where $AttrValue is declared like this,
String AttrValue = element.getAttribute("attemptid"); ( this extracts
attemptid value from /RootElement/colAttempt/Attempt). Code gets
compiled with no problem. But during run time, I get NPE.

java.lang.NullPointerException
at
com.sun.org.apache.xpath.internal.jaxp.JAXPVariableStack.getVariableOrPara
m(Unknown Source)
at
com.sun.org.apache.xpath.internal.operations.Variable.execute(Unknown
Sour
ce)
at
com.sun.org.apache.xpath.internal.operations.Operation.execute(Unknown
Sou
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,008
Messages
2,570,269
Members
46,871
Latest member
Stephendes

Latest Threads

Top