zoukankan      html  css  js  c++  java
  • 一些常用的XPath语法

    https://files.cnblogs.com/bear831204/XPathTest.zip

    部分代码:

    WriteElements("The root bookstore, this is the whole document:",
                    "./bookstore");
                WriteElements("All <first-name> elements:",
                    ".//first-name");
                WriteElements("First <author> inside each <book>:",
                    ".//book/author[1]");
                WriteElements("Last <author> inside each <book>:",
                    ".//book/author[last()]");
                WriteElements("First <author> from the entire set of <author> elements within <book> elements:",
                    "(.//book/author)[1]");
                WriteElements("First <author> inside first <book>:",
                    ".//book[1]/author[1]");
                WriteElements("All <author> elements that contain at least one <degree> element child and at least one <award> element child:",
                    ".//author[degree and award]");
                WriteElements("All <author> elements that contain at least one <degree> or <award> element and at least one <publication> element:",
                    ".//author[(degree or award) and publication]");
                WriteElements("The third <author> element that has a <first-name> child element:",
                    "(.//author[first-name])[3]");
                WriteElements("All <book> elements whose style attribute value is equal to the specialty attribute value of the <bookstore> element at the root of the document:",
                    ".//book[/bookstore/@specialty=@style]");
                WriteElements("All <degree> elements one or more levels deep in the <bookstore> element (arbitrary descendants):",
                    "./bookstore//degree");
                WriteElements("All elements with the style attribute:",
                    ".//*[@style]");
                WriteElements("First 2 <author> inside each <book>:",
                    ".//book/author[position() < 3]");
                WriteElements("All <author> elements that contain at least one <last-name> element child with the value Bob:",
                    ".//author[last-name = 'Bob']");
                WriteElements("All <author> elements that has a <last-name> child element with the value Bob and a <first-name> child element with the value Joe:",
                    ".//author[last-name = 'Bob' and first-name = 'Joe']");
                WriteElements("All <author> elements that do no contain <award> child elements with the value Pulitzer, inculding the author doesn't have award and has award but the value is not Pulitzer:",
                    ".//author[not(award = 'Pulitzer')]");
                WriteLog("The count of book element:" + "    (count(.//book))");
                WriteLog(_doc.XPathEvaluate("count(.//book)").ToString());
                WriteLog();
                WriteElements("All <author> elements that has a <first-name> child element with the value contains 'Ton':",
                    ".//author[contains(first-name,'Ton')]");
                WriteElements("All elements whose name contains st",
                    ".//*[contains(name(),'st')]");
                WriteElements("All first-name and last-name elements:",
                    ".//*[name() = 'first-name' or name() = 'last-name']");
                WriteElements("All elements whose name starts with publica:",
                    ".//*[starts-with(name(),'publica')]");
                WriteElements("All elements whose name starts with my:",
                    ".//*[starts-with(name(),'my')]");
                WriteElements("All elements whose local name is author:",
                    ".//*[local-name()='author']");
                WriteElements("All elements whose value is misery:",
                    ".//*[.='misery']");
                WriteElements("All <author> elements whose value is Matthew Bob:",
                    ".//author[. = 'Matthew Bob']");
                WriteElements("All author elements containing any child element whose value is Bob:",
                    ".//author[* = 'Bob']");

  • 相关阅读:
    探究 encode 和 decode 的使用问题(Python)
    C语言结构体在内存中的存储情况探究------内存对齐
    文件基本操作 (C语言)
    利用Xamaria构建Android应用-公交发车信息屏
    ChakraCore ,Net托管编程
    Go并发与.Net TAP
    码农视角
    让isis支持高德地图
    Fedora Server 上配置 MariaDb 集群
    .Net Sokcet 异步编程
  • 原文地址:https://www.cnblogs.com/bear831204/p/2501628.html
Copyright © 2011-2022 走看看