Hi Suzanne,
Yes, there's a namespace binding in the document, but Xalan does not make
assumptions about what namespace bindings are in the source document. For
example, there could be multiple bindings for the prefix "m" in one source
document. Which would the XPath processor pick? A namespace prefix is a
lexical representation of the namespace URI -- it has no meaning of its
own.
Here's a small example:
<doc>
<m:node xmlns:m="http://foo.com">1</m:node>
<n:node xmlns:m="http://foo.com" />2</n:node>
<m:node xmlns:m="http://bar.com" />3</m:node>
<n:node xmlns:m="http://bar.com" />4</n:node>
</doc>
Now, if you want to use XPath to query the document, you might do something
like this:
/doc/m:node
So, which nodes should this XPath find? If your environment binds the
namespace prefix "m" to the string "http://foo.com" the query will return
references to nodes 1 and 2. If it binds it to the string
"http://bar.com", it will return references to nodes 3 and 4.
There is no semantic analysis of namespace URIs -- they are simply strings
that are compared for equality. If the URI is an HTTP URL, it does not
imply that the processor de-references that URL.
The reason SimpleXPathAPI has a binding for the prefix "SOAP-ENV" is
because it's using the document element to look for namespace bindings.
Unfortunately, the binding for the prefix "m" is on the node where it's
first used, and SimpleXPathAPI is not using that node to resolve namespace
prefixes.
Does that answer your question?
Dave
Suzanne Dirkers
<[EMAIL PROTECTED] To: [EMAIL PROTECTED]
com> cc: (bcc: David N
Bertoni/Cambridge/IBM)
Subject: Re: SimpleXPathAPI and a
soap.xml
03/14/2003 05:43
AM
Please respond
to xalan-dev
Hi,
What exactly do we mean by 'namespace binding on the element?'
It seems to me that there is a definition for what m: is on the m:getTemp
element...namely, "urn:xmethods-Temperature"...??? Does that not define
what m is? Or are we messed up because we also need a definition for urn:
?
<m:getTemp xmlns:m="urn:xmethods-Temperature"
I notice it understands SOAP-ENV: ok. This also is defined in
the element, but does this pass because XPath understands what http: is?
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
Suzanne
David N
Bertoni/Cambridge To:
[EMAIL PROTECTED]
/IBM cc:
<david_n_bertoni@ Subject: Re: SimpleXPathAPI
and a soap.xml
us.ibm.com>
03/13/2003 05:04
PM
Please respond to
xalan-dev
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