Ori Doolman wrote:
Hello,
I'm quite new to Xalan and Xpath, and I have a problem extracting a node
text from an XML document.
I'm trying to extract the text node of CheckCustomerPINResult in the
following document:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:xsd="http://www.w3.org/2001/XMLSchema";> <soap:Body>
                <CheckCustomerPINResponse
xmlns="http://www.SigValue.com/SVCrm";>
        
<CheckCustomerPINResult>xyz</CheckCustomerPINResult>
                        <ErrCode>1234</ErrCode>
                </CheckCustomerPINResponse>
        </soap:Body>
</soap:Envelope>

I'm trying the following test using the supplied example:

SimpleXPathAPI.exe d:\response.xml /
/soap:Envelope/soap:Body/CheckCustomerPINResponse/CheckCustomerPINResult
/text()

But I get no output.

I noticed that if I remove the default namespace from
CheckCustomerPINResponse or even if I use a prefix like
<CheckCustomerPINResponse
xmlns:myprefix="http://www.SigValue.com/SVCrm";> then I do get the right
value 'xyz'.

I tried reading the mailing lists and searched the internet, but still
didn't find a way to extract the text() when the default namespace
exist.
The only suggested solutions are changing the document to have a prefix.
This is something I cannot do, because the document is not generated by
me. It is a response from a soap server.

This is a FAQ:

http://xml.apache.org/xalan-j/faq.html#faq-N101EE
http://www.dpawson.co.uk/xsl/sect2/N5536.html#d6682e1012


Another thing I don't understand: why should I use the 'soap' prefix at
all? For as much as I know the prefix is arbitrary and what really
important is the URI. Therefore, I expected that the following
expression (assuming I remove the default namespace) would work too, but
it doesn't.

In an XPath expression, the prefix is _not_ arbitrary. If you remove the default namespace, it doesn't affect the elements in the SOAP namespace.

/Envelope[namespace-uri()='http://schemas.xmlsoap.org/soap/envelope/']/B
ody[namespace-uri()='http://schemas.xmlsoap.org/soap/envelope/']/CheckCu
stomerPINResponse/CheckCustomerPINResult/text()

Isn't this expression equivalent to the first one I wrote above?

No.  You need to understand namespaces:

http://www.dpawson.co.uk/xsl/sect2/N5536.html

If you really want to use the namespace-uri() function, you could use something like this:

/*[local-name() = 'Envelope' and namespace-uri()='http://schemas.xmlsoap.org/soap/envelope/']/*[local-name() = 'Body' and namespace-uri()='http://schemas.xmlsoap.org/soap/envelope/']/CheckCu
stomerPINResponse/CheckCustomerPINResult/text()

Dave

Reply via email to