I am having a problem with an "*" in an XPath working
correctly. The XPath syntax seems correct, but the
Node is not selected.
I am including a small, standalone Java test program
that demostrates this problem. The XML document is a
static String in the source file. Please let me know
if you see any problems with it. Here is what I get
when I run the program:
C:\>java -cp
.;dom4j.jar;xercesImpl.jar;xml-apis.jar;jaxen.jar Test
toDate = FAIL
Regards,
Dave
import java.util.HashMap;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Node;
import org.dom4j.XPath;
public class Test
{
private static final Map NAMESPACE_URIS = new
HashMap();
static
{
NAMESPACE_URIS.put("rr",
"http://www.mwvis.com/interfaces/ReportRequest.xsd");
NAMESPACE_URIS.put("xqx",
"http://www.w3.org/2003/12/XQueryX");
NAMESPACE_URIS.put("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
}
private static final String REQUEST_DOCUMENT
= "<rr:ReportRequest
name=\"MisplacedItemsHistory\""
+ "
xmlns:rr=\"http://www.mwvis.com/interfaces/ReportRequest.xsd\""
+ "
xmlns:xqx=\"http://www.w3.org/2003/12/XQueryX\""
+ "
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+ " <rr:Specification responseType=\"Xml\"
returnTotalRecords=\"true\">"
+ " <rr:CountPerPage>20</rr:CountPerPage>"
+ " <rr:Page>4</rr:Page>"
+ " <rr:UserId>6</rr:UserId>"
+ " </rr:Specification>"
+ " <xqx:whereClause>"
+ " <xqx:expr xsi:type=\"operatorExpr\"
infix=\"true\">"
+ " <xqx:opType>and</xqx:opType>"
+ " <xqx:parameters>"
+ " <xqx:expr
xsi:type=\"operatorExpr\" infix=\"true\">"
+ "
<xqx:opType>>=</xqx:opType>"
+ " <xqx:parameters>"
+ " <xqx:expr
xsi:type=\"stringConstantExpr\">"
+ "
<xqx:value>DateMisplaced</xqx:value>"
+ " </xqx:expr>"
+ " <xqx:expr
xsi:type=\"stringConstantExpr\">"
+ " <xqx:value>2004-06-01
00:00:00.000000</xqx:value>"
+ " </xqx:expr>"
+ " </xqx:parameters>"
+ " </xqx:expr>"
+ " <xqx:expr
xsi:type=\"operatorExpr\" infix=\"true\">"
+ "
<xqx:opType><=</xqx:opType>"
+ " <xqx:parameters>"
+ " <xqx:expr
xsi:type=\"stringConstantExpr\">"
+ "
<xqx:value>DateMisplaced</xqx:value>"
+ " </xqx:expr>"
+ " <xqx:expr
xsi:type=\"stringConstantExpr\">"
+ " <xqx:value>2004-07-01
00:00:00.000000</xqx:value>"
+ " </xqx:expr>"
+ " </xqx:parameters>"
+ " </xqx:expr>"
+ " </xqx:parameters>"
+ " </xqx:expr>"
+ " </xqx:whereClause>"
+ "</rr:ReportRequest>";
private static final String XPATH_TO_DATE_NODE
=
"/rr:ReportRequest/xqx:whereClause/*/xqx:expr["
+ "@xsi:type = 'operatorExpr' "
+ "and xqx:opType = '<=' "
+ "and xqx:parameters/xqx:expr[1]/xqx:value =
'DateMisplaced']"
+ "/xqx:parameters/xqx:expr[2]/xqx:value";
public static void main(String[] args)
{
try {
Document requestDoc =
DocumentHelper.parseText(REQUEST_DOCUMENT);
String toDate = getToDate(requestDoc);
System.out.println("toDate = " + toDate);
} catch (Exception e) {
e.printStackTrace(System.out); }
} /* main */
private static String getToDate(Document
requestDoc)
{
Node toDateNode = null;
XPath xpath = null;
xpath =
requestDoc.createXPath(XPATH_TO_DATE_NODE);
xpath.setNamespaceURIs(NAMESPACE_URIS);
toDateNode = xpath.selectSingleNode(requestDoc);
return (null == toDateNode) ? "FAIL" :
toDateNode.getText();
} /* getToDate */
} /* Test */
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
dom4j-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user