[xquery-talk] Newbie Q: Saxon-B, xmlns
Michael Malak
michaelmalak at yahoo.com
Tue Jul 3 14:50:40 PDT 2007
I'm attempting to use Saxon-B with C#/.NET.
string xhtml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<html _xml3a_lang=\"en\" lang=\"en\"
xmlns=\"http://www.w3.org/1999/xhtml\">"
+ "<head><title>Hello World</title></head></html>";
string query = "data(/html/head/title)";
Processor processor = new Processor();
XmlDocument input = new XmlDocument();
input.LoadXml(xhtml);
XQueryCompiler compiler = processor.NewXQueryCompiler();
XQueryExecutable exp = compiler.Compile(query);
XQueryEvaluator eval = exp.Load();
eval.ContextItem = processor.NewDocumentBuilder().Build(new
XmlNodeReader(input));
Serializer qout = new Serializer();
StringWriter sw = new StringWriter();
qout.SetOutputProperty(Serializer.METHOD, "xml");
qout.SetOutputWriter(sw);
eval.Run(qout);
Console.WriteLine(sw);
When I execute this as-is, I get back an empty XML document. If I
change the xmlns attribute to be xmlns:html, it works. I presume
that's because that removes the HTML elements out of the default
namespace and Saxon-B is not schema aware so it happily processes the
HTML tags as if they're not HTML.
How can I change my query so that it works with the source XHTML above
as-is?
More information about the talk
mailing list