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

From: [] On Behalf Of Ryan Puddephatt
Sent: 31 May 2008 01:03
Subject: [saxon] Loading Namespaces into a Document


                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?







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




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