Hi all together,

I have a question concerning XPath evaluation with Dom4J.

Here the relevant Java code snippet of my program:

private Document createConfirmationXML(String generatePDF, String validatePrev, String createdFlag, String statusMessage) { if (xmlConfirmationDoc == null) // first creation of confirmation Doc
       {
xmlConfirmationDoc = DocumentFactory.getInstance().createDocument(); confirmation = xmlConfirmationDoc.addElement("confirmation").addAttribute("generate_pdf", generatePDF) .addAttribute("week", week).addAttribute("validate_prev", validatePrev) .addAttribute("xsi:noNamespaceSchemaLocation", "confirmations.xsd"); confirmation.add(new org.dom4j.Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance";)); confPrev = confirmation.addElement("prevision").addAttribute("id", prevId).addAttribute("created", createdFlag);
           confPrev.addElement("status").addText(statusMessage);
       }
       else // in case confirmation doc already exists
       {
// it has to be checked if a <prevision> element for the given prevId already exists
          Map uris = new HashMap();
          uris.put("xsi", "http://www.w3.org/2001/XMLSchema-instance";);
XPath xpath = xmlConfirmationDoc.createXPath("/confirmation/[EMAIL PROTECTED]'" + prevId + "']");
          xpath.setNamespaceURIs(uris);
List results = xpath.selectNodes(xmlConfirmationDoc); if (results.size() == 0) // <prevision> element does not already exist for the given prevId
           {
confPrev = confirmation.addElement("prevision").addAttribute("id", prevId).addAttribute("created", createdFlag);
               confPrev.addElement("status").addText(statusMessage);
           }
           else // <prevision> element already exists for the given prevId
           {
for (Iterator iterator = results.iterator(); iterator.hasNext();)
               {
                   Element confPrevision = (Element)iterator.next();
confPrevision.addElement("status").addText(statusMessage);
               }
           }
       }
       return xmlConfirmationDoc;
   }

And this is an example for a confirmation.xml that has to be generated and parsed:

<?xml version="1.0" encoding="UTF-8"?>
<confirmation generated_pdf="true" week="2003-02-01" validated_prev="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="confirmations.xsd">
   <prevision id="L_2003123" created="true">
         <status>prevision created successfully</status>
   </prevision>
</confirmation>

For me my Java code looks correct. However, if I run the program, I always get an error stating that the XPath expression in the following line is invalid: XPath xpath = xmlConfirmationDoc.createXPath("/confirmation/[EMAIL PROTECTED]'" + prevId + "']");

The weird thing is that if I test the same XPath expression with XML-Spy I get the requested <prevision> node.
I am currently using DOM4J 1.6.1. with Java 4 (can't use Java 6 at work).

I would be very happy, if someone can help me fix that issue.

Best regards,
Oliver Schneider
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to