In W3C spec terms, the namespaces are part of the static context for the XPath expression. In the Saxon API, this means they must be predeclared using declareNamespace() on the XPathCompiler object (which is Saxon's implementation of the static context). There's no direct way in this API of extracting the namespaces from the source document and making them part of the static context for the XPath expression, though you can do it of course using a separate query using in-scope-prefixes() and namespace-uri-for-prefix().
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Ryan Puddephatt
Sent: 31 May 2008 01:03
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Loading Namespaces into a Document

Hi,

                I have the following .Net code

 

            XdmNode definitionsDoc = _processor.NewDocumentBuilder().Build(new Uri(@"Definitions.xml"));

            XPathSelector xpath = _processor.NewXPathCompiler().Compile("/definitions/p:def").Load();

            xpath.ContextItem = definitionsDoc;

            XdmValue nodes = xpath.Evaluate();

 

But I get an exception because the ‘p’ namespace isn’t defined, why isn’t it picked up by the document? Is there away to make Saxon do this?

 

I get the same problem with System.Xml.XmlDocument so I’m not sure if this is an underlying problem?

 

Thanks

 

Ryan

 

-----------------------------------------------

Ryan Puddephatt

FIX Developer

Fidessa LatentZero

1 Alfred Place

London WC1E 7EB

t: +44 (0) 20 7323 6112

b: +44 (0) 79 8539 2458

f: +44 (0) 20 7462 4242

e: rpuddephatt@latentzero.com

w: http://www.latentzero.com

 


_______________________________________________________________________
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

_____________________________________________________________________
This e-mail has been scanned for viruses by Verizon Business Internet Managed Scanning Services - powered by MessageLabs. For further information visit http://www.mci.com