You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by le...@jpmchase.com on 2005/06/29 14:30:41 UTC

Xpath Rule and Default namespace

I am using xalan 1.9 with xerces 2.6.0. Using the sample code provided
(SimpleXPathAPI) I get unexpected results when I use an XML document
that contains a default namespace.

I expected this xpath rule to return true but it returns false as I
believe
that the default name space is ignored.

./SimpleXPathAPI ./example.xml /FpML:FpML /FpML:FpML/IrML/irTrade/party/
FpML:partyTradeIdentifier/FpML:tradeId=55007835
The string value of the result is:
false

If I remove the default namespace in example.xml or add a prefix to the
namespace. Then the xpath will rule will return _true_ 

./SimpleXPathAPI ./example.xml /FpML:FpML /FpML:FpML/IrML/irTrade/party/
FpML:partyTradeIdentifier/FpML:tradeId=55007835
The string value of the result is:
true

The above xpath evaluates to TRUE with and without the default namespace
using another processor. Is this a xalan bug or my misunderstanding of
XML namespaces?

Thanks in advance
Lee Dittrich


Example XML used in above test

<?xml version="1.0" encoding="UTF-8"?>
<FpML:FpML xmlns:FpML="http://www.fpml.org/2003/FpML-4-0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:IrML="http://irml.com/2003/trade"
xmlns="http://irml.com/2003/trade" version="4-0">
	<FpML:header>
		<FpML:messageId
messageIdScheme="TEST">5554667</FpML:messageId>
		<FpML:sentBy>MySystem</FpML:sentBy>
		<FpML:sendTo>TradeCaptureSystem</FpML:sendTo>
		<FpML:copyTo>IntradaySystem</FpML:copyTo>
	
<FpML:creationTimestamp>2004-07-13T15:38:00</FpML:creationTimestamp>
	</FpML:header>
	<IrML version="4-0">
		<irTrade>
			<FpML:tradeHeader>
				<FpML:partyTradeIdentifier>
					<FpML:partyReference
href="PARTY"/>
	
<FpML:tradeId>55007835</FpML:tradeId>
				</FpML:partyTradeIdentifier>
		</irTrade>
	</IrML>
</FpML:FpML>

Re: Xpath Rule and Default namespace

Posted by da...@us.ibm.com.
> I am using xalan 1.9 with xerces 2.6.0. Using the sample code provided
> (SimpleXPathAPI) I get unexpected results when I use an XML document
> that contains a default namespace.
> 
> I expected this xpath rule to return true but it returns false as I
> believe

It's an "expression," not a rule.

> that the default name space is ignored.
> 
> ./SimpleXPathAPI ./example.xml /FpML:FpML /FpML:FpML/IrML/irTrade/party/
> FpML:partyTradeIdentifier/FpML:tradeId=55007835
> The string value of the result is:
> false

This is a FAQ:

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

Note that implementing this with the XPathEvaluator class almost always 
involves a programmatic solution.  You search the archives of the list, as 
this has been asked many times, so there should be some good source code 
snippets.

> The above xpath evaluates to TRUE with and without the default namespace
> using another processor. Is this a xalan bug or my misunderstanding of
> XML namespaces?

I don't know what processor you're using that returns true, but Xalan-C is 
correct, and the XPath standard is explicit about this:

http://www.w3.org/TR/xpath#node-tests

"A QName in the node test is expanded into an expanded-name using the 
namespace declarations from the expression context. This is the same way 
expansion is done for element type names in start and end-tags except that 
the default namespace declared with xmlns is not used: if the QName does 
not have a prefix, then the namespace URI is null (this is the same way 
attribute names are expanded). It is an error if the QName has a prefix 
for which there is no namespace declaration in the expression context."

Dave