Results 1 to 1 of 1
  1. #1
    fassfouss is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default parsing an xml file and executing an XPATH querry

    Hello,

    I have an xml file

    My goal is displayed only the part when the text is equal. This code display all the file

    if i try this code, it doesn't work

    Java Code:
    XPath xpath = XPathFactory.newInstance().newXPath();
                String expression = "/postes/poste";
                InputSource inputSource = new InputSource("postes.txt");
                Node nodes =(Node) xpath.evaluate(expression, inputSource, XPathConstants.NODE);
    the error message is on this line `Node nodes =(Node) xpath.evaluate(expression, inputSource, XPathConstants.NODE)`; `inputSource can not be resolved`

    and if i try this code

    Java Code:
     XPathFactory xPathFactory = XPathFactory.newInstance();
                // To get an instance of the XPathFactory object itself.
                XPath xPath = xPathFactory.newXPath();
                // Create an instance of XPath from the factory class.
                String expression = "/postes/poste[gouvernorat=text]";
                XPathExpression xPathExpression = xPath.compile(expression);
        
                // Compile the expression to get a XPathExpression object.
                Object result = xPathExpression.evaluate(R.raw.postes);
                //Evaluate the expression against the XML Document to get the result.
    The error is in to lines `xPath.compile(expression);` and `xPathExpression.evaluate(R.raw.postes);`

    i added this import javax.xml.xpath.*;

    but it doesn't work

    I Try DOM Parser but it doesn't work also ; i can't read the file

    please help me

    Thank you in advance.
    Last edited by fassfouss; 04-03-2011 at 08:41 PM.

Similar Threads

  1. Parsing XML file using Xpath in jdk1.4
    By ziggy in forum New To Java
    Replies: 7
    Last Post: 02-27-2011, 12:55 PM
  2. Replies: 0
    Last Post: 05-12-2010, 11:11 AM
  3. Problems with parsing using XPath
    By thooom in forum XML
    Replies: 6
    Last Post: 04-26-2010, 09:47 AM
  4. Problems with XPath (XML Parsing)
    By thooom in forum New To Java
    Replies: 6
    Last Post: 04-25-2010, 04:56 PM
  5. Replies: 0
    Last Post: 11-13-2009, 09:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •