• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XPath issue in Java

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the next XML document: http://dl.dropbox.com/u/19952564/docs/yweather-bogota.xml

And I need to extract attribute values from:



i.e: Tue, 9, 17, Cloudy, 26.

I have the following Java code:



But it does not print anything.

In http://www.xpathtester.com/test I paste the XML document, and it prints the results I expect for //yweather:forecast[1]/@* XPath expression.

Can you give some suggestions about this case.

Java SDK's XPath version is correct?

Thanks in advance for your response.

So long.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see where you told the XPathExpression what namespace the "yweather" prefix represents. You have to provide the XPath object with a NamespaceContext.

(By the way, in English: "I have the following Java code".)
 
Jhon Ortiz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, Paul Clapham, I don't know how to accomplish that task.

Can you guide me or give me some ideas to accomplish that task?

Thanks in advance.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What part of it are you having trouble with?
 
Jhon Ortiz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul Clapham,

Can you show me a simple example about extract attribute values from an XML element like: <yweather:forecast day="Tue" date="24 Apr 2012" low="9" high="17" text="Cloudy" code="26" />

Or you can give me some ideas or suggestions to do that using XPath from Java?

Thanks in advance for your invaluable help!

So long.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand. You already have a simple example, all you have to do to that example is to create a NamespaceContext object and assign it to the XPath object by calling the method which I believe is called setNamespaceContext(). That is the only idea or suggestion that you need.
 
Jhon Ortiz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have solved this (thanks Paul Chapham)

I have used this class (found in: http://goo.gl/Ko97M):



My own method now looks like this:






So long.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic