*
The moose likes XML and Related Technologies and the fly likes Extracting attributes from xml with xpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Extracting attributes from xml with xpath" Watch "Extracting attributes from xml with xpath" New topic
Author

Extracting attributes from xml with xpath

thomas colding
Ranch Hand

Joined: Mar 23, 2007
Posts: 60
Hi
I am trying to extract the attributes from the follwing xml but it does not work.

Any suggestion what I am doing wrong.


My xml



The code I use:



Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
You said it does not work but failed to indicate the error messages received and provided very little code. That said, I can see a possible problem or two from the little info you did provide.
At I think you really want XPathExpression
In the call to

you are passing the interface Document instead of the reference to document.
You're trying to do something with emailNodes when you probably mean phoneNodes.
And I don't believe there is a getAttribute(String) method on the Node API You probably want something more like


Have another read on th API. Hope this didn't give away a homework assignment.
K Abhijit
Ranch Hand

Joined: Mar 03, 2008
Posts: 88
what is


shouldn't it be



... Also post error if you are facing any


“The difference between 'involvement' and 'commitment' is like an eggs-and-ham breakfast: the chicken was 'involved' - the pig was 'committed'.”
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

I'll move this to our XML forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
thomas colding
Ranch Hand

Joined: Mar 23, 2007
Posts: 60
Rob Prime wrote:I'll move this to our XML forum.


Correct my mistake, I was to fast posting the answer
thomas colding
Ranch Hand

Joined: Mar 23, 2007
Posts: 60
Ed Ward wrote:You said it does not work but failed to indicate the error messages received and provided very little code. That said, I can see a possible problem or two from the little info you did provide.
At I think you really want XPathExpression
In the call to

you are passing the interface Document instead of the reference to document.
You're trying to do something with emailNodes when you probably mean phoneNodes.
And I don't believe there is a getAttribute(String) method on the Node API You probably want something more like


Have another read on th API. Hope this didn't give away a homework assignment.


Yes I should, Is it API for XPath.
Jhon Ortiz
Greenhorn

Joined: May 28, 2009
Posts: 16
Hi thomas colding,

Do you know how to extract the attributes for the next element:



I have tried through with various ways, but I have no received the expected results.

Some suggestions? Thanks in advance.

So long!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Extracting attributes from xml with xpath
 
Similar Threads
Ajax, Struts, and a few pesky event based issues
How to get Events associated with DOM elements ?
change result xml element name
Help needed for executing Sybase stored procedure using Hibernate
Jboss 5.1.0 jsp:root not working