代码之家  ›  专栏  ›  技术社区  ›  Younes

XmlNodeList筛选节点的xPath

  •  1
  • Younes  · 技术社区  · 15 年前
    XmlNodeList list = null;
    list = xmlResult.SelectNodes("/sitecore
                                   /result
                                    /item
                                     [scWebsitePath='"+sitecoreContextItemPath+"'
                                      and scTemplateId='"+templateId+"' 
                                      and scDateCreated > '"+publishedFrom+"' 
                                      and scDateCreated < '"+publishedTo+"']");
    

    如果给定的路径是“xxx/yyy/zzz/”,并且我希望返回该路径下的项,那么是否也可以对路径(即“xxx/yyy/zzz/”是节点的一部分)进行xPath检查:

    • “xxx/yyy/zzz/abc/def/ghi”<-将 有效的
    • “xxx/yyy/zzz/abc/def/ghi/jkl”<-将
    • “xxx/yyy/zzz/aaa/aaa/zzz”<-不会是 有效的

    我可以通过执行以下操作来访问节点路径:

    XmlNode thisScPath = node.SelectSingleNode("scPath");
    if (thisScPath == null)
    continue;
    

    所以我想知道我是否也可以做一些类似的事情:

    list = xmlResult.SelectNodes("/sitecore
                                   /result
                                    /item[scWebsitePath='"+sitecoreContextItemPath+"'
                                          and scTemplateId='"+templateId+"'
                                          and scDateCreated > '"+publishedFrom+"'
                                          and scDateCreated < '"+publishedTo+"'
                                          and scPath = '"+scPath+"/*']");
    

    1 回复  |  直到 15 年前
        1
  •  1
  •   Martin Honnen    15 年前

    我想你想查一下

      and contains(scPath, 'xxx/yyy/zzz/')
    

    或

      and starts-with(scPath, 'xxx/yyy/zzz/')
    

    如果使用XPath 2.0实现 http://www.xqsharp.com/ 然后甚至可以使用正则表达式和matches函数。