例如,对于下面的xml
<CATALOG>
<CD title="Empire Burlesque"/>
<CD title="empire burlesque"/>
<CD title="EMPIRE BURLESQUE"/>
<CD title="EmPiRe BuRLeSQuE"/>
<CD title="Others"/>
<CATALOG>
Run Code Online (Sandbox Code Playgroud)
如何将前4条记录与xpath匹配//CD[@title='empire burlesque'].是否有xpath函数来执行此操作?其他解决方案,如PHP函数也被接受.
我试图lower-case在XPath中使用函数匹配国家或国家.translate有点凌乱,所以使用小写和我的Python版本2.6.6具有XPath 2.0支持我相信,因为小写只在XPath 2.0中可用.
我如何能在我的案例中使用小写字符是我正在寻找的.希望这个例子是自我解释的.我正在寻找['USA', 'US']输出(两个国家一次性如果小写评估国家和国家是相同的,可能会发生).
HTML:doc.htm
<html>
<table>
<tr>
<td>
Name of the Country : <span> USA </span>
</td>
</tr>
<tr>
<td>
Name of the country : <span> UK </span>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
Python:
import lxml.html as lh
doc = open('doc.htm', 'r')
out = lh.parse(doc)
doc.close()
print out.xpath('//table/tr/td[text()[contains(. , "Country")]]/span/text()')
# Prints : [' USA ']
print out.xpath('//table/tr/td[text()[contains(. , "country")]]/span/text()')
# Prints : [' UK ']
print out.xpath('//table/tr/td[lower-case(text())[contains(. , "country")]]/span/text()')
# Prints : [<Element …Run Code Online (Sandbox Code Playgroud) 我想从td中仅提取文本的一部分,例如"FLAC".如何使用XPath完成?
我试过// text()[contains(.,'FLAC')],但是它返回了整个文本.
<tr>
<td class="left">Format plików</td>
<td>
AVI, FLV, RM, RMVB, FLAC, APE, AAC, MP3, WMA, OGG, BMP, GIF, TXT, JPEG, MOV, MKV, DAT, DivX, XviD, MP4, VOB
</td>
</tr>
Run Code Online (Sandbox Code Playgroud) 我有一个类似问题,即XPath忽略大小写的SelectNodes问题,但在我的情况下,大写/小写问题是在名称为“ application”的节点中(有时是“ Application”,有时是“ application”)。
我将如何应用其他帖子的解决方案?还是在这种情况下适用另一种?
xml:
<?xml version="1.0" encoding="utf-16" ?>
<application>
<forms>
<action type="update">
<form uid="" >
</form>
</action>
</forms>
</application>
Run Code Online (Sandbox Code Playgroud)
在C#3.5中:
XmlNode nodex= oXMLDoc1.SelectSingleNode("Application/forms/action/form/@uid")
nodex.Value="UniqueIDx";//nodex is null :S
Run Code Online (Sandbox Code Playgroud)