我已经尝试过使用XPath表达式从下面的元素中获取该项目,但它似乎对我有点误导。
我想用XPath找到的字符串是
Excel VBA用户表单视频| Excel VBA表格第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>
答案 0 :(得分:1)
我用XSLT样式表测试了你的XPath表达式,结果是那个
"//h1[@class='gamma']"
DID WORK ,
但表达方式
"//h1[@class="gamma"]"
无法工作。
简单的区别在于引号的类型:
'
)。"
),这可能会与您查询的周围引号冲突。因此,请检查报价的类型,您可能会解决问题。