xpath2 - XPath2.Extensions 1.0.10-ci-1876
Non-official extensions for XPath2.dll
PM> Install-Package XPath2.Extensions -Version 1.0.10-ci-1876 -Source https://www.myget.org/F/xpath2/api/v3/index.json
> nuget.exe install XPath2.Extensions -Version 1.0.10-ci-1876 -Source https://www.myget.org/F/xpath2/api/v3/index.json
> dotnet add package XPath2.Extensions --version 1.0.10-ci-1876 --source https://www.myget.org/F/xpath2/api/v3/index.json
source https://www.myget.org/F/xpath2/api/v3/index.json
nuget XPath2.Extensions ~> 1.0.10-ci-1876
Copy to clipboard
> choco install XPath2.Extensions --version 1.0.10-ci-1876 --source https://www.myget.org/F/xpath2/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "xpath2" -SourceLocation "https://www.myget.org/F/xpath2/api/v2"
Install-Module -Name "XPath2.Extensions" -RequiredVersion "1.0.10-ci-1876" -Repository "xpath2" -AllowPreRelease
Copy to clipboard
Browse the sources in this package using Visual Studio or WinDbg by configuring the following legacy symbol server URL: https://www.myget.org/F/xpath2/symbols/
XPath2.Net : Lightweight XPath2 for .NET
This is an implementation of W3C XML Path Language (XPath) 2.0 for .NET Framework based on standard XPathNavigator API. The given implementation based on practice of developing XQuery is fully corresponding to the specification demands.
Project is copied and forked from https://xpath2.codeplex.com/. Original credits go to Semyon A. Chertkov.
Build
Quality | |
Build Azure | |
CodeFactor | |
Sonar Quality Gate | |
Sonar Bugs | |
Sonar Code Smells | |
Sonar Coverage | |
NuGet | |
XPath2 | |
XPath2.Extensions | |
MyGet (previews) | |
XPath2 | |
XPath2.Extensions |
Supported frameworks
- .NET 3.5
- .NET 4.0 and up
- .NET Standard 2.0 & 2.1
- Mono 4 and up
Info
It conforms for 12954 * from 15133 (85.60%) regarding the test-set XQTSCatalog.xml
(XQTS 1.0.2 Nov. 20, 2006) at https://dev.w3.org/2006/xquery-test-suite/PublicPagesStagingArea/
* Note that depending on your system, you can get 12958 to work. This is because of some tests which test the lowercase functionality from 'K' (Kelvin-sign). More details see this question.
API used is an anology to the standard one built into the platform: you utilize XPath2Expression instead of the common XPathExpression and a set of extension functions for XNode, XPathNavigator and XmlNode classes.
System.Xml.XPath | WmHelp.XPath2 |
---|---|
XPathNavigator.Evaluate() | XPathNavigator.XPath2Evaluate() |
XmlNode.SelectNodes() | XmlNode.XPath2SelectNodes() |
XmlNode.SelectSingleNode() | XmlNode.XPath2SelectSingleNode() |
XNode.Select | XNode.XPath2Select |
..., etc. | ..., etc. |
In addition there parameterized XPath2 expressions are implemented that allow to compose XQuery requests by standard Linq-to-XML means. Though it is not generally necessary to use XPath during writing Linq-to-XML queries nevertheless they allow to make it simple. To pass variable values into XPath expression we use C# 4.0 anonimous structures, e.g. new creates variable $varname,... inside XPath expression.
Here are examples of some W3C XQuery usecases and their translations into C# and LINQ.
XQuery (RQ2.xq)
<result>
{
for $i in doc("items.xml")//item_tuple
let $b := doc("bids.xml")//bid_tuple[itemno = $i/itemno]
where contains($i/description, "Bicycle")
order by $i/itemno
return
<item_tuple>
{ $i/itemno }
{ $i/description }
<high_bid>{ max($b/bid) }</high_bid>
</item_tuple>
}
</result>
C#
XNode items = XDocument.Load("items.xml");
XNode bids = XDocument.Load("bids.xml");
XNode result = new XDocument(
new XElement("result",
(from item in items.XPath2SelectElements("//item_tuple")
.OrderBy((elem) => (string)elem.Element("itemno"))
let bid = bids.XPath2Select<XElement>("//bid_tuple[itemno = $i/itemno]", new { i = item })
where ((string)item.Element("description")).Contains("Bicycle")
select new XElement("item_tuple",
item.Element("itemno"),
item.Element("description"),
!bid.Any() ? null :
new XElement("high_bid",
bid.AsQueryable().Max((elem) => (double)elem.Element("bid"))))))
);
XQuery (RQ3.xq)
<result>
{
for $u in doc("users.xml")//user_tuple
for $i in doc("items.xml")//item_tuple
where $u/rating > "C"
and $i/reserve_price > 1000
and $i/offered_by = $u/userid
return
<warning>
{ $u/name }
{ $u/rating }
{ $i/description }
{ $i/reserve_price }
</warning>
}
</result>
C#
XNode users = XDocument.Load("users.xml");
XNode items = XDocument.Load("items.xml");
XNode result =
new XElement("result",
(from user in users.XPath2SelectElements("//user_tuple")
from item in items.XPath2SelectElements("//item_tuple")
where (bool)XPath2Expression.Evaluate(@"$u/rating > 'C' and $i/reserve_price > 1000
and $i/offered_by = $u/userid", new { u = user, i = item })
select new XElement("warning",
user.Element("name"),
user.Element("rating"),
item.Element("description"),
item.Element("reserve_price"))));
XQuery (RQ9.xq)
<result>
{
let $end_dates := doc("items.xml")//item_tuple/end_date
for $m in distinct-values(for $e in $end_dates
return month-from-date($e))
let $item := doc("items.xml")
//item_tuple[year-from-date(end_date) = 1999
and month-from-date(end_date) = $m]
order by $m
return
<monthly_result>
<month>{ $m }</month>
<item_count>{ count($item) }</item_count>
</monthly_result>
}
</result>
C#
XNode items = XDocument.Load("items.xml");
var endDates = items.XPath2SelectElements("//item_tuple/end_date");
XNode result =
new XElement("result",
(from month in XPath2Expression.SelectValues(@"distinct-values(for $e in $end_dates
return month-from-date($e))", new { end_dates = endDates }).OrderBy((arg) => arg)
let item = items.XPath2SelectElements(@"//item_tuple[year-from-date(end_date) = 1999
and month-from-date(end_date) = $m]", new { m = month })
select new XElement("monthly_result",
new XElement("month", month),
new XElement("item_count", item.Count())
)));
See ReleaseNotes.md
-
.NETFramework 3.5
- Newtonsoft.Json (>= 6.0.8)
- XPath2 (>= 1.0.10-ci-1876)
-
.NETFramework 4.0
- Newtonsoft.Json (>= 6.0.8)
- XPath2 (>= 1.0.10-ci-1876)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 11.0.2)
- XPath2 (>= 1.0.10-ci-1876)
- .NETFramework 3.5: 3.5.0.0
- .NETFramework 4.0: 4.0.0.0
- .NETStandard 2.0: 2.0.0.0
Assembly | Assembly hash | Match |
---|---|---|
/lib/netstandard2.0/xpath2.extensions.dll | 75825a4977404d4cb6d7f981351387561 |
OwnersStef |
AuthorsStef Heyenrath |
Project URLhttps://github.com/StefH/XPath2.Net |
LicenseMS-PL |
TagsXPath XPath2 XPath2.0 Xml W3C XQuery XQTS Extensions |
Info36 total downloads |
3 downloads for version 1.0.10-ci-1876 |
Download (15.17 KB) |
Download legacy symbols (29.72 KB) |
Found on the current feed only |
Package history
Version | Size | Last updated | Downloads | Mirrored? | |||
---|---|---|---|---|---|---|---|
1.1.5 | 24.44 KB | Fri, 06 Sep 2024 13:56:23 GMT | 2 | ||||
1.1.4 | 24.46 KB | Fri, 22 Mar 2024 11:00:02 GMT | 4 | ||||
1.1.3 | 24.44 KB | Tue, 28 Nov 2023 21:09:57 GMT | 6 | ||||
1.1.2 | 20.14 KB | Mon, 25 Apr 2022 14:44:14 GMT | 4 | ||||
1.1.1 | 20.14 KB | Tue, 22 Jun 2021 16:33:16 GMT | 3 | ||||
1.1.0 | 20.01 KB | Fri, 18 Jun 2021 19:39:01 GMT | 3 | ||||
1.0.12 | 19.95 KB | Sun, 06 Sep 2020 19:38:57 GMT | 3 | ||||
1.0.11 | 19.95 KB | Fri, 08 May 2020 06:14:23 GMT | 5 | ||||
1.0.10-ci-1879 | 15.16 KB | Wed, 11 Sep 2019 18:44:04 GMT | 3 | ||||
1.0.10-ci-1876 | 15.17 KB | Wed, 11 Sep 2019 12:32:46 GMT | 3 |