Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2008

Tip: Looking for answers? Try searching our database.

Why does this XPath not work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Thielen - 21 Jul 2008 04:45 GMT
This XPath works fine:
/order/customer[(./address/@zip = 80302) and
(starts-with(./name,'J'))]

But this XPath :
/order/customer[(./address/@zip = 80302) and (ends-with(./name,'J'))]

ends-with() is standard XPath but I get the error: Namespace manager
or XsltContext needed.

??? - thanks - dave

david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
David Thielen - 21 Jul 2008 04:50 GMT
Same issue with matches()

>This XPath works fine:
>/order/customer[(./address/@zip = 80302) and
[quoted text clipped - 13 lines]
>
>Cubicle Wars - http://www.windwardreports.com/film.htm

david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
Steven Cheng [MSFT] - 21 Jul 2008 05:28 GMT
#XPath 1.0 Functions
--------------------
>From: David Thielen <thielen@nospam.nospam>
>Subject: Re: Why does this XPath not work
>Date: Sun, 20 Jul 2008 21:50:42 -0600

>Same issue with matches()
>
[quoted text clipped - 21 lines]
>
>Cubicle Wars - http://www.windwardreports.com/film.htm
Steven Cheng [MSFT] - 21 Jul 2008 05:38 GMT
Hi Dave,

Regarding on the error "Namespace manager or XsltContext needed." you
encountered, it is due to the "ends-with" function is not a standard
function in XPATH 1.0.( it is in XPATH 2.0).  Currently, .net framework XML
components only implemented XPATH 1.0 and XSLT 1.0 function set, here is
the list of supported functions:

#XPath 1.0 Functions
http://www.edankert.com/xpathfunctions.html

#4.2 String Functions
http://www.w3.org/TR/xpath#section-String-Functions

for your scenario, you may use some other built-in functions to replace the
ends-with call or define some .net custom extension functions:

============use substring to detect end of string============
private void btnQuery_Click(object sender, EventArgs e)
       {
           XmlDocument doc = new XmlDocument();
           doc.Load(@"..\..\data.xml");


           string xpath =
"/root/customers/customer[substring(./name,string-length(./name),1)='e']";

           XmlNodeList nodes = doc.SelectNodes(xpath);

           if (nodes != null && nodes.Count > 0)
           {
               foreach (XmlNode node in nodes)
                   MessageBox.Show(node.OuterXml);
           }
       }
=============================

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: David Thielen <thielen@nospam.nospam>
>Subject: Re: Why does this XPath not work
>Date: Sun, 20 Jul 2008 21:50:42 -0600

>Same issue with matches()
>
[quoted text clipped - 21 lines]
>
>Cubicle Wars - http://www.windwardreports.com/film.htm
David Thielen - 21 Jul 2008 16:55 GMT
OK - thanks

>Hi Dave,
>
[quoted text clipped - 93 lines]
>>
>>Cubicle Wars - http://www.windwardreports.com/film.htm

david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.