ShahbazAli

Hi,
I am using Microsoft.XQuery.dll to integrate XQuery in my ASP.NET application to search an XML Document.I have XML like:

< xml version="1.0" >
<E-MAILS>
<MessageID ID="1">
<Priority>Normal</Priority>
<Sensitive />
<DateCreated>5/28/2007 3:30:59 PM</DateCreated>
<DateReceived>5/28/2007 3:30:59 PM</DateReceived>
<FromName></FromName>
<From></From>
<ReplyTo></ReplyTo>
<To></To>
<cc />
<Bcc />
<Subject></Subject>
<TextBody></TextBody>
<HtmlBody></HtmlBody>
<Header />
<Attachments />
<Size></Size>
</MessageID>

<MessageID ID="2">
<Priority>Normal</Priority>
<Sensitive />
<DateCreated>5/28/2007 3:30:59 PM</DateCreated>
<DateReceived>5/28/2007 3:30:59 PM</DateReceived>
<FromName></FromName>
<From></From>
<ReplyTo></ReplyTo>
<To></To>
<cc />
<Bcc />
<Subject></Subject>
<TextBody></TextBody>
<HtmlBody></HtmlBody>
<Header />
<Attachments />
<Size></Size>
</MessageID>
</E-MAILS>

I am using following code;

string xpath = "//MessageID/[From[contains(text(), ' " + from + " ')]]";
// where 'from' is holding some text to compare

XQueryNavigatorCollection navColInbox = new XQueryNavigatorCollection();
navColInbox.AddNavigator(xmlInboxDoc.CreateNavigator(), "xqt");
string cxpath = "<E-MAILS>{document('xqt')" + xpath +"}</E-MAILS>";
XQueryExpression expr = new XQueryExpression(cxpath);
XQueryNavigator nav = expr.Execute(navColInbox);
XmlDocument doc2 = new XmlDocument();
doc2.LoadXml(nav.ToXml());

the doc2 is successfully created with the searched nodes but when I used the following XPath

string xpath = "//MessageID/[To[contains(text(), ' " + to + " ')]]";

an XQueryException is thrown "Expected XPath Axis where 'TO' encountered" .
Can anyone help me with this situation I am waiting.. Thanks





Re: XML and the .NET Framework Error in XQuerying (Expected XPath Axis where 'TO' encountered)

Martin Honnen

First of all Microsoft.XQuery.dll is not part of the .NET framework, I think it was an early preview that is now not longer supported. As for your XPath, instead of

string xpath = "//MessageID/[To[contains(text(), ' " + to + " ')]]";

try

Code Snippet

string xpath = "//MessageID[To[contains(text(), ' " + to + " ')]]";






Re: XML and the .NET Framework Error in XQuerying (Expected XPath Axis where 'TO' encountered)

ShahbazAli

yes you are right.. but this library does what I want.. Actually I want to search the node and then from create the xml document which is then provided to the XslTransform object to show in the aspx page.

any hint





Re: XML and the .NET Framework Error in XQuerying (Expected XPath Axis where 'TO' encountered)

Sergey Dubinets - MSFT

Load XPathDocument.

Create XPathNavigator for it.

Search node with SelectSingleNode(). It returns you navigator.

Pass this navigator to XslCompiledTransform.Transform.

XslCompiledTransform would start transformation from the node you pass (XslTransform move navigator to root), so you would not need to reload your node to new tree.

Please note: The node you pass would not match "/"

See "Specifying starting mode" in the http://blogs.msdn.com/xmlteam/articles/Introducing_XslCompiledTransform.aspx.