【问题标题】:Trouble creating an appropriate XPath expression创建适当的 XPath 表达式时遇到问题
【发布时间】:2017-04-11 22:05:55
【问题描述】:

我已经尝试了很多使用 XPath 表达式从下面的元素获取项目,但这对我来说似乎有点误导。
我想用 XPath 定位的字符串是

Excel VBA 用户表单视频 | Excel VBA Forms Pt 1 - 绘图表格

我试过的 XPath 表达式是:

//h1[@class="gamma"]/text()

我的 XML 代码是:

<div class="woVideoShowPost">

    <h1 class="gamma">
        Excel VBA videos | Excel VBA Part 2 - Writing Your First Macro
    </h1>

    <p class="woVideoPosted">
        Posted by 
        <a href="/videos/author/andrewgould.htm">Andrew Gould</a>
         on 10 May 2013
    </p>

    <p>VBA, or Visual Basic for Applications, is a powerful tool that you can use to automate Microsoft Excel. This video introduces you to the basics of writing code in the VB Editor, including how to create a new module, how to write a subroutine, some best practice guidelines for laying out your code and adding comments, and how to write simple VBA instructions. We'll also show you how to run the simple procedure that you'll write, and how to ensure that you can save your code and reopen the file which contains it.</p>

    <p></p>

    <div class="woVideoWrapper">
        <div class="woVideoWrapped">
            <iframe width="100%" height="100%" src="http://www.youtube.com/embed/7RVGdA9AhrY" allowfullscreen=""></iframe>
        </div>
    </div>

    <p class="woVideoShowTipTitle">You can increase the size of the video:</p>


    <div class="woVideoShowTip">

        <img alt="Full screen mode for YouTube" src="../../files/videos/images/youtube.jpg">
        <p>You can view the video in full screen mode as shown on the left, using the icon at the bottom right of the frame.</p>

    </div>

    <p class="woVideoShowTipTitle">You can also increase the quality of the video:</p>

    <div class="woVideoShowTip">

        <img alt="Changing resolution" src="../../files/videos/images/youtube2.jpg">
        <p>
            You can improve the resolution of the video using another icon at the bottom right of the frame.  This will slow down the connection speed,
            but increase the display and sound quality. This icon only becomes visible when you start playing the video.
        </p>

    </div>

    <p class="woVideoShowTipTitle">
        Finally, if nothing happens when you play the video, check that you're not using <a href="../../blog/s312/compatibility-view.htm">IE in compatibility view</a>.

    </p>
</div>

【问题讨论】:

  • 您的 XPath 表达式看起来不错:在什么方面它“似乎具有误导性”?
  • 你显然做错了什么,我不知道是什么。对不起!

标签: xml xpath


【解决方案1】:

我使用 XSLT 样式表测试了您的 XPath 表达式,结果是这样的

"//h1[@class='gamma']"

成功了
但是表达式

"//h1[@class="gamma"]"

不起作用

简单的区别在于引号的类型:

  • 在第一个变体中,字符串 'gamma' 周围有单引号 (')。
  • 在第二个变体中,字符串“gamma”周围有双引号 ("),这可能会与您查询的周围引号冲突。

所以检查你的报价类型,你可能会解决你的问题。

【讨论】:

  • @SMth80:我非常感谢您的评论,并注意到我的 edit 的修订。我尊重你的决定,但由于我对它们缺乏了解,我不会进一步参与。所以也请尊重这个决定。
猜你喜欢
  • 1970-01-01
  • 2015-11-14
  • 1970-01-01
  • 1970-01-01
  • 2011-04-12
  • 1970-01-01
  • 2022-01-15
  • 2012-06-02
  • 1970-01-01
相关资源
最近更新 更多