aspose file tools*
The moose likes XML and Related Technologies and the fly likes Invalid XPath expression while trying to parse a path with attribute in DOM parser. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Invalid XPath expression while trying to parse a path with attribute in DOM parser." Watch "Invalid XPath expression while trying to parse a path with attribute in DOM parser." New topic
Author

Invalid XPath expression while trying to parse a path with attribute in DOM parser.

Bharath Raja
Ranch Hand

Joined: Jan 21, 2009
Posts: 111
I've a xml file as follow.


Now I wanna to get the parent attribute for the corresponding name attribute(which was input from user). I'm using the selectSingleNode() method of dom parser and I've given the xpath as "//sources/source/[@name='PropertySetter']", which leads the Invalidpath exception. Please find the java code below.



I got the exception as below.
org.dom4j.InvalidXPathException: Invalid XPath expression: //sources/source/[@name ='PropertySetter' Expected one of '.', '..', '@', '*', <QName>....

Suggestion please...

Life is either daring something or nothing - Helen Keller
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
>Now I wanna to get the parent attribute for the corresponding name attribute
If I interprete it correctly, the xpath I would use would be this.

Use such as getText() would give you directly the attribute parent's setting.
Bharath Raja
Ranch Hand

Joined: Jan 21, 2009
Posts: 111
Paul Clapham wrote:

it works thank you...
Bharath Raja
Ranch Hand

Joined: Jan 21, 2009
Posts: 111
g tsuji wrote:>Now I wanna to get the parent attribute for the corresponding name attribute
If I interprete it correctly, the xpath I would use would be this.

Use such as getText() would give you directly the attribute parent's setting.

awesome :D
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid XPath expression while trying to parse a path with attribute in DOM parser.