Hi Suzanne,
You must provide a way to bind a namespace prefix to a namespace URI when
you use the XPathEvaluator API. If you look at the source code, that's the
parameter that's the PrefixResolver. We provide a short cut by letting you
pass a XalanElement node instance as a node in the document where the
namespace declaration for "m" exists.
XPath is a specification that is meant to be embedded in an environment
which provides context for it. One of the parts of that context is a set
of namespace bindings. When you do XSLT, those bindings are provided by
the stylesheet document. When you do standalone XPath, there is no
standard way to do this. SampleXPathAPI uses the document element to
attempt to resolve prefixes, which may or may not work for any particular
document
Some comments on some of you XPath expressions (Context and
XPathExpression):
/SOAP-ENV:Envelope/SOAP-ENV:Body zipcode
This won't work because zipcode is not a child of SOAP-ENV:Body. Try
these instead:
/SOAP-ENV:Envelope/SOAP-ENV:Body .//zipcode
/SOAP-ENV:Envelope/SOAP-ENV:Body ./*/zipcode
/SOAP-ENV:Envelope/SOAP-ENV:Body/m:getTemp zipcode
This won't work because there's no namespace binding for "m" in scope
on the document element. You can't do anything about this using the
sample program, although you could do something if you write your own
application.
By the way, you may want to join and post the the Xalan-C user list.
Hope that helps...
Dave
Suzanne Dirkers
<[EMAIL PROTECTED] To: [EMAIL PROTECTED]
com> cc: (bcc: David N
Bertoni/Cambridge/IBM)
Subject: SimpleXPathAPI and a soap.xml
03/13/2003 12:50
PM
Please respond
to xalan-dev
Folks,
I tried out seeing if I could use XPATH inside Xalan to retrieve
the zipcode out of this xml file soap.xml just from using the
SimpleXPathAPI executable.
I am not an Xpath expert yet but I couldn't find any way to get
to the zipcode that didn't either produce no result, an exception, or a
message about 'no such context node exists'. It especially seemed to
absolutely hate the node that starts with 'm:getTemp' . Any time I tried to
reference that node it either gave me an exception or claimed that node did
not exist. I'm baffled, because it looks to me like it SHOULD exist. And
I know this xml file should be good xml because you can run it in a java
program that executes SOAP and it works.
Does anybody know why Xalan would not understand any nodes in
this file below <SOAP-ENV:Body> ??
<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<m:getTemp xmlns:m="urn:xmethods-Temperature"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<zipcode xsi:type="xsd:string">94041</zipcode>
</m:getTemp>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Some of the commands I tried with SimpleXPathAPI and their
results looked like these:
:\buildarea\xml-xalan\c\samples\SimpleXPathAPI>simplexpathapi
soap.xml /SOAP-ENV:Envelope/SOAP-ENV:Body zipcode
The string value of the result is:
(no result)
--> :\buildarea\xml-xalan\c\samples\SimpleXPathAPI>simplexpathapi
soap.xml /SOAP-ENV:Envelope/SOAP-ENV:Body/m:getTemp zipcode
Exception caught!
This one above is the one I thought should seriously work!!
:\buildarea\xml-xalan\c\samples\SimpleXPathAPI>simplexpathapi
soap.xml /SOAP-ENV:Envelope/SOAP-ENV:Body m:getTemp/child::zipcode
Exception caught!
\buildarea\xml-xalan\c\samples\SimpleXPathAPI>simplexpathapi
soap.xml /SOAP-ENV:Envelope/SOAP-ENV:Body ../m:getTemp/chid::zipcode
Exception caught!
\buildarea\xml-xalan\c\samples\SimpleXPathAPI>simplexpathapi
soap.xml /zipcode zipcode
Warning -- No nodes matched the location path "/zipcode".
Execution cannot continue...
Basically, I'm getting the feeling here you have to specify the
whole path in the context node all the way down to the parent of zipcode
here or it won't work...apparently it looks only 1 level deep for 'nodes'.
But what on earth its problem is with m:getTemp, I have no idea. Apparently
it doesn't consider that a real node. Does anybody know why?
Thanks,
Suzanne