Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extracting attributes from xml with xpath

 
thomas colding
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is


shouldn't it be



... Also post error if you are facing any
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll move this to our XML forum.
 
thomas colding
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic