我知道有一些在线正则表达式评估器..非常有用,实时匹配.它们就像RegexBuddy的Web应用程序.
我想知道xPath选择器是否有类似的东西?我只是在学习它们,这对我来说很有价值.
是否有一个在线测试器,允许您输入XML,然后是xPath选择器和匹配(现场会更好,但我怀疑有人编写了JavaScript解释器吗?)吗?
谢谢
拥有这样的XML文档:
<?xml version="1.0" encoding="UTF-8"?>
<records type="array">
<record>
<name>svn</name>
<record-type>A</record-type>
<ttl type="integer">86400</ttl>
<zone-id type="integer">69075</zone-id>
<aux type="integer">0</aux>
<id type="integer">xxx</id>
<active>Y</active>
<data>xxx.xxx.xxx.xxx</data>
</record>
<record>
<name>domain.tld.</name>
<record-type>NS</record-type>
<ttl type="integer">86400</ttl>
<zone-id type="integer">xxx</zone-id>
<aux type="integer">0</aux>
<id type="integer">xxx</id>
<active>Y</active>
<data>domain.tld.</data>
</record>
<record>
<name>blog</name>
<record-type>A</record-type>
<ttl type="integer">86400</ttl>
<zone-id type="integer">xxx</zone-id>
<aux type="integer">0</aux>
<id type="integer">xxx</id>
<active>Y</active>
<data>xxx.xxx.xxx.xxx</data>
</record>
</records>
Run Code Online (Sandbox Code Playgroud)
如何将具有兄弟/记录/记录/记录类型的所有/记录/记录/ 名称与值"A" 匹配?
我有以下XML:
<List xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<Fields>
<Field>
</Field>
</Fields>
</List>
Run Code Online (Sandbox Code Playgroud)
这是从SharePoint Web服务返回的XML的精简版本.我也有以下xPath:
/List/Fields/Field
Run Code Online (Sandbox Code Playgroud)
当我xmlns从我的XML中删除xPath工作正常.当它在那里时我的xPath什么都没找到.我的xPath应该做些什么?修改XML不是一种选择.
我真的不知道XSL但是我需要修复这个代码,我已经减少了它以使它更简单.
我收到了这个错误
无效的XSLT/XPath函数
在这条线上
<xsl:variable name="text" select="replace($text,'a','b')"/>
Run Code Online (Sandbox Code Playgroud)
这是XSL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:inm="http://www.inmagic.com/webpublisher/query" version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:preserve-space elements="*" />
<xsl:template match="text()" />
<xsl:template match="mos">
<xsl:apply-templates />
<xsl:for-each select="mosObj">
'Notes or subject'
<xsl:call-template
name="rem-html">
<xsl:with-param name="text" select="SBS_ABSTRACT" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="rem-html">
<xsl:param name="text" />
<xsl:variable name="text" select="replace($text, 'a', 'b')" />
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
谁能告诉我它有什么问题?
我正在写一个Selenium测试用例.这是我用来匹配数据表中所有"修改"按钮的xpath表达式.
//img[@title='Modify']
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何通过索引访问匹配的节点集?我试过了
//img[@title='Modify'][i]
Run Code Online (Sandbox Code Playgroud)
和
//img[@title='Modify' and position() = i]
Run Code Online (Sandbox Code Playgroud)
但是都不起作用..我也试过XPath checker(一个firefox扩展).发现总共有13个匹配,然后我完全不知道如何选择其中一个.. 或者XPath是否支持指定选择不在同一父节点下的节点?
我想只选择一个名为.date的类
出于某种原因,我不能让这个工作.如果有人知道我的代码有什么问题,我将不胜感激.
@$doc = new DOMDocument();
@$doc->loadHTML($html);
$xml = simplexml_import_dom($doc); // just to make xpath more simple
$images = $xml->xpath('//[@class="date"]');
foreach ($images as $img)
{
echo $img." ";
}
Run Code Online (Sandbox Code Playgroud) <grand id="grand">
<parent>
<child age="18" id="#not-grand"/>
<child age="20" id="#grand"/> <!-- This is what I want to locate -->
</parent>
</grand>
Run Code Online (Sandbox Code Playgroud)
有谁能告诉我如何表达定位第二个孩子?
这不起作用......
"/grand/parent/child[@id=concat('#',/grand/@id)]/@age"
Run Code Online (Sandbox Code Playgroud)
谢谢.
对不起.表达式还可以.我发现我在其他领域遇到了一些问题而不是表达本身.
正如标题所说,是否有可能在XPath中选择仅以某个字符串开头的元素,但也许不会以相同的结尾?
例如,有3个锚元素:
<a href="buy.php/onething"></a><a href="buy.php/twothing"></a><a href="sell.php/anotherthing"></a>
Run Code Online (Sandbox Code Playgroud)
我只想获得以'buy.php /'开头的锚元素.我认为以下内容不会起作用,是吗:
getByXPath("//a[@href='buy.php/']")
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
Interestingly, pandas I/O tools does not maintain a read_xml() method and the counterpart to_xml(). However, read_json proves tree-like structures can be implemented for dataframe import and read_html for markup formats.
Now, if the pandas team does consider such a read_xml method for a future pandas version, what implementation would they pursue: parsing with built-in xml.etree.ElementTree with its iterfind() or iterparse() functions or the third-party module, lxml with its XPath 1.0 and XSLT 1.0 methods?
下面是我在一个简单,扁平,以元素为中心的XML输入上的四种方法类型的测试运行.所有这些都设置为root的任何二级子级的基因化解析,并且每个方法应该产生完全相同的pandas数据帧.除了pd.Dataframe()字典列表上的最后一次调用之外的所有内容.该XSLT转换的方法,以XML为CSV铸造StringIO()在 …
考虑以下XML:
<response>
<status_code>200</status_code>
<status_txt>OK</status_txt>
<data>
<url>http://bit.ly/b47LVi</url>
<hash>b47LVi</hash>
<global_hash>9EJa3m</global_hash>
<long_url>http://www.tumblr.com/docs/en/api#api_write</long_url>
<new_hash>0</new_hash>
</data>
</response>
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种非常简短的方法来获得<hash>元素的价值.我试过了:
var hash = xml.Element("hash").Value;
Run Code Online (Sandbox Code Playgroud)
但那不起作用.是否可以提供XPath查询XElement?我可以使用旧System.Xml框架来执行此操作,执行以下操作:
xml.Node("/response/data/hash").Value
Run Code Online (Sandbox Code Playgroud)
在LINQ命名空间中是否有这样的东西?
更新:
在对此进行了一些讨论之后,我找到了一种方法来做我正在尝试做的事情:
var hash = xml.Descendants("hash").FirstOrDefault().Value;
Run Code Online (Sandbox Code Playgroud)
我仍然有兴趣看看是否有人有更好的解决方案?