[Pkg-mono-devel] Problem with XPath in Mono

Tomasz Rybak bogomips@post.pl
Fri, 08 Oct 2004 12:25:40 +0200


I've written program:

using System;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

class Klasa {
	public static int Main(string [] argv)
	{
		Console.WriteLine(argv[1]);
		XPathDocument xpd = new XPathDocument(new XmlTextReader(argv[0]),
XmlSpace.Preserve);
		XPathNavigator xpn = xpd.CreateNavigator();
		XPathExpression xpe = xpn.Compile(argv[1]);
		Console.WriteLine(xpe.ReturnType);
		switch (xpe.ReturnType) {
			case XPathResultType.NodeSet:
				XPathNodeIterator i = xpn.Evaluate(xpe) as XPathNodeIterator;
				while (i.MoveNext()) {
					if (null == i.Current) {
						Console.WriteLine("null");
					} else {
						Console.WriteLine("*{0}* {1} *{2}* {3}", i.Current.Name,
i.Current.LocalName, i.Current.NamespaceURI, i.Current.NodeType);
					}
				}
				Console.WriteLine("Juz");
				break;
		}
		
		
		return 0;
	}
};

I'm using it on this XML file:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.playboy.com/" xmlns:a="http://www.playboy.com/a"
xmlns:b="http://www.playboy.com/b">
	<child atribute="0"/>
	<a:child atribute="0"/>
	<a:child atribute="0" a:atribute="1" b:atribute="2">
		<chil atribute="3"/>
	</a:child>
	<child a:atribute="0"/>
	<a:child at0="0" a:at1="1" b:at2="2"/>
</root>

Here are the results:
tomus@barad-dur:~/Programming/Mono$ ./xpath.exe przyklad.xml '/root'
/root
NodeSet
Juz
tomus@barad-dur:~/Programming/Mono$ ./xpath.exe przyklad.xml '/*'
/*
NodeSet
*root* root *http://www.playboy.com/* Element
Juz
tomus@barad-dur:~/Programming/Mono$

Am I doing something wrong, or Mono has bug in XPath implementation?
Adding namespaces and prefixes doesn't help.
I tried this program on Mono 1.0.1 from Debian archives, and 
on Mono 1.0.2, compiled by me, and it run the same in both cases.

-- 
Tomasz Rybak <bogomips@post.pl>