Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath C在规则中指定什么查询语言来拉出两个book节点_Xpath_C# 3.0_Xquery - Fatal编程技术网

Xpath C在规则中指定什么查询语言来拉出两个book节点

Xpath C在规则中指定什么查询语言来拉出两个book节点,xpath,c#-3.0,xquery,Xpath,C# 3.0,Xquery,嗨, 目前,我有一个基于规则的系统,其中传入的xml消息与规则匹配,如果规则命中,则处理数据包。为了获得匹配,我使用xpath来选择xml中的各个值,并在规则中将这些值指定为组合的xpath:regexp表达式,类似这样 /书店/书籍[1]/标题:+ 例如,上述内容将与日常意大利语相匹配 但是我试图找到一个查询或者一个新的查询语言表达式,它允许我为上面的经典msdn docs book.xml选择所有的book节点,这样,如果我在规则中指定查询表达式,我可以使用解析器将其提取出来,并直接对xml

嗨, 目前,我有一个基于规则的系统,其中传入的xml消息与规则匹配,如果规则命中,则处理数据包。为了获得匹配,我使用xpath来选择xml中的各个值,并在规则中将这些值指定为组合的xpath:regexp表达式,类似这样

/书店/书籍[1]/标题:+

例如,上述内容将与日常意大利语相匹配

但是我试图找到一个查询或者一个新的查询语言表达式,它允许我为上面的经典msdn docs book.xml选择所有的book节点,这样,如果我在规则中指定查询表达式,我可以使用解析器将其提取出来,并直接对xml文件使用它来提取books节点

我不知道xpath是否能做到这一点。我在看XQuery,但它似乎很冗长。XSLT可能可以做到这一点,但它太冗长了。任何想法

这是一种指定表达式的简单方法,它可以提升所有book节点,或者说1和2,或者1和3

谢谢。
Bob.

以下问题,哪一个设计不同,间接地回答了这个问题


使用xquery和flwor:

<?xml version="1.0" encoding="ISO-8859-1"?>
  <bookstore>

      <book category="COOKING"> 
        <title lang="en">Everyday Italian</title>
        <author>Giada De Laurentiis</author>    
        <year>2005</year>
       <price>30.00</price>
      </book>

      <book category="CHILDREN">
       <title lang="en">Harry Potter</title>
       <author>J K. Rowling</author>
       <year>2005</year>
       <price>29.99</price>
      </book>

      <book category="WEB">
       <title lang="en">XQuery Kick Start</title>
       <author>James McGovern</author>
       <author>Per Bothner</author>
       <author>Kurt Cagle</author>
       <author>James Linn</author>
       <author>Vaidyanathan Nagarajan</author>
       <year>2003</year>
       <price>49.99</price>
      </book>

      <book category="WEB">
       <title lang="en">Learning XML</title>
       <author>Erik T. Ray</author>
       <year>2003</year>
       <price>39.95</price>
      </book>

    </bookstore>

where子句可以找到每个图书节点的位置,只返回特定的节点。

为什么要按索引而不是按其他标准(如标题关键字、年份等)获取结果?在某些情况下,它可能是值,但在其他情况下,我希望按索引捕获结果。另外,我在这里展示的xml并不是我所使用的xml的真实表示。我不能展示它。任何关于如何做的想法。我不认为它需要从索引中提取。如果表达式选择category=WEB,那么我想选择节点中的所有子节点。但我想允许规则编写者选择按索引进行选择。目前,我正在寻找整理设计。上下快速移动
nicholas@mordor:~/flwor/position$ 
nicholas@mordor:~/flwor/position$ basex position.xq 
<book category="children">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>
<book category="web">
  <title lang="en">XQuery Kick Start</title>
  <author>James McGovern</author>
  <author>Per Bothner</author>
  <author>Kurt Cagle</author>
  <author>James Linn</author>
  <author>Vaidyanathan Nagarajan</author>
  <year>2003</year>
  <price>49.99</price>
</book>nicholas@mordor:~/flwor/position$ 
nicholas@mordor:~/flwor/position$ 
nicholas@mordor:~/flwor/position$ cat position.xq 

xquery version "3.1";

let $doc := doc("bookstore.xml")
let $books := $doc/bookstore/book

for $book at $p in $books 
where $p gt 1 and $p lt 4
return $book
nicholas@mordor:~/flwor/position$ 
nicholas@mordor:~/flwor/position$ cat bookstore.xml 
<bookstore>
  <book category="cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
  <book category="children">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="web">
    <title lang="en">XQuery Kick Start</title>
    <author>James McGovern</author>
    <author>Per Bothner</author>
    <author>Kurt Cagle</author>
    <author>James Linn</author>
    <author>Vaidyanathan Nagarajan</author>
    <year>2003</year>
    <price>49.99</price>
  </book>
  <book category="web">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>nicholas@mordor:~/flwor/position$