XPathSelector: Invalid URI: The URI is empty.
Added by Anonymous almost 18 years ago
Legacy ID: #4091030 Legacy Poster: Brian Lalonde (brianiac)
I'm getting an error when trying to use the doc() or doc-available() function in an XPath selector in C#. I think this could be related to bug 1505250 or http://sourceforge.net/forum/message.php?msg_id=3785892 or https://sourceforge.net/forum/message.php?msg_id=3768422 , but I'm not sure. Here is some minimal code to show the error I'm getting. test.xml <a/> test.cs using System; using Saxon.Api; class Program { static void Main(string[] args) { Processor Saxon = new Processor(); XPathCompiler xpc = Saxon.NewXPathCompiler(); foreach (string xpath in new string[] {"document-uri(/)","base-uri(/)", "doc-available('file:///C:/Projects/test.xml')"} ) { Console.WriteLine("XPath: {0}", xpath); XPathExecutable xpe = xpc.Compile(xpath); XPathSelector selector = xpe.Load(); DocumentBuilder docb = Saxon.NewDocumentBuilder(); Uri testxml = new Uri("file:///C:/Projects/test.xml"); selector.ContextItem = docb.Build(testxml); XdmValue selected = selector.Evaluate(); Console.WriteLine("Selected {0} items: {1}", selected.Count, selected.ToString()); } } } command line to compile csc /nologo /debug test.cs /r:C:\Tools\Saxon\bin\saxon8api.dll && test.exe output XPath: document-uri(/) Selected 1 items: file:///C:/Projects/test.xml XPath: base-uri(/) Selected 1 items: file:///C:/Projects/test.xml XPath: doc-available('file:///C:/Projects/test.xml') Unhandled Exception: System.UriFormatException: Invalid URI: The URI is empty. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Uri..ctor(String uriString) at net.sf.saxon.dotnet.DotNetURIResolver.makeAbsolute(String href, String base) at net.sf.saxon.functions.Document.makeDoc(String href, String baseURL, XPathContext c, SourceLocator locator) at net.sf.saxon.functions.Doc.doc(XPathContext context) at net.sf.saxon.functions.Doc.evaluateItem(XPathContext context) at net.sf.saxon.expr.ComputedExpression.iterate(XPathContext context) at Saxon.Api.XPathSelector.Evaluate() at Program.Main(String[] args) in c:\Projects\test.cs:line 19
Replies (2)
RE: XPathSelector: Invalid URI: The URI is em - Added by Anonymous almost 18 years ago
Legacy ID: #4092232 Legacy Poster: Michael Kay (mhkay)
As a workaround, please set the BaseUri property on the XPathCompiler object. Any valid URI will do. Given that the URI you supplied to the doc-available() function is an absolute URI, it would be friendlier if it worked even in the absence of a base URI in the static context. The code is designed to do that, but it's not working because the base URI held internally is "" when the code is testing for null. I'll fix that for the next release. Michael Kay http://www.saxonica.com/
Workaround - Added by Anonymous almost 18 years ago
Legacy ID: #4095251 Legacy Poster: Brian Lalonde (brianiac)
Works great. Thanks!
Please register to reply