1 Reply Latest reply: Nov 17, 2008 11:04 AM by DrClap RSS

    dom4j InvalidXPathException problem

    807589
      Hi,
                      <textItem id="1">
      
                     <title>first</title>
      
                     <displayText>number one</displayText>
      
                     <displayGraphic filename="uno"/>
      
                </textItem>
      xp = DocumentHelper.createXPath("//textItem@id");
      When I run the above xpath expression on the xml code I get :

      org.dom4j.InvalidXPathException: Invalid XPath expression: //hotTextItem@id Unexpected '@'
      at org.dom4j.xpath.DefaultXPath.parse(DefaultXPath.java:360)
      at org.dom4j.xpath.DefaultXPath.<init>(DefaultXPath.java:59)
      at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
      at org.dom4j.DocumentHelper.createXPath(DocumentHelper.java:121)

      I am sure that this is the correct xpath string to use. Is it?

      thanks,
      Hugh
        • 1. Re: dom4j InvalidXPathException problem
          DrClap
          inabind wrote:
          I am sure that this is the correct xpath string to use. Is it?
          That looks remarkably silly, as the second sentence directly contradicts the first sentence. And you really know that it isn't correct, don't you? Try not to get caught up in wishful thinking and egoistic behaviour. It just gets in the way of problem-solving.

          Anyway, no, that isn't a valid XPath expression. (That's what the error message says.) I expect your next question would have been how to make it correct, but that can't be answered without knowledge of what the expression was intended to find.