Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Need help - extract node using JAVA Xpath

Thread view: 
brahatha - 05 Jun 2007 21:04 GMT
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 - 05 Jun 2007 21:07 GMT
> 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
[quoted text clipped - 49 lines]
>
> NEED HELP!

I tried this as suggested by Martin Honnen,
/RootElement/colAttempt/*[starts-with(name(),'Attempt')]/
ResultElement/nodeList/NodeIwant
I get NPE.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.