- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,我正在尝试从这个 XML 中获取所有艺术家:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadata created="2015-02-03T04:03:18.468Z"
xmlns="http://musicbrainz.org/ns/mmd-2.0#"
xmlns:ext="http://musicbrainz.org/ns/ext#-2.0">
<artist-list count="6310" offset="0">
<artist id="d51955f3-df06-432c-a90d-0308f3c48273" type="Person" ext:score="100">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<gender>male</gender>
<country>US</country>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
</area>
<begin-area id="82f3a697-ba65-404d-a1ed-360147af7d10">
<name>San Diego</name>
<sort-name>San Diego</sort-name>
</begin-area>
<end-area id="ae0110b6-13d4-4998-9116-5b926287aa23">
<name>California</name>
<sort-name>California</sort-name>
</end-area>
<disambiguation>jazz pianist, composer, arranger and bandleader</disambiguation>
<life-span>
<begin>1922-04-17</begin>
<end>2013-06-29</end>
<ended>true</ended>
</life-span>
<alias-list>
<alias sort-name="Smith, Paul T.">Paul T. Smith</alias>
</alias-list>
</artist>
<artist id="443ead81-02ce-4136-a759-71453184c002" type="Person" ext:score="100">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<gender>male</gender>
<country>US</country>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
</area>
<begin-area id="f83bde89-c84a-4846-a89a-d5d0874e9ddc">
<name>Calumet</name>
<sort-name>Calumet</sort-name>
</begin-area>
<end-area id="6db2e45d-d7f3-43da-ac0b-7ba5ca627373">
<name>Glendale</name>
<sort-name>Glendale</sort-name>
</end-area>
<disambiguation>film and television composer, Disney Legends honoree</disambiguation>
<life-span>
<begin>1906-10-30</begin>
<end>1985-01-25</end>
<ended>true</ended>
</life-span>
<alias-list>
<alias sort-name="Smith, Paul J.">Paul J. Smith</alias>
</alias-list>
</artist>
<artist id="fac3e6c4-6d3c-4086-a590-95e4a057ac42" ext:score="95">
<name>Paul Smith</name>
<sort-name>Paul Smith</sort-name>
<disambiguation>Banjo</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="8ffc42c7-4083-4435-b91c-6ddf4095eeb3" ext:score="95">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<country>US</country>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
</area>
<disambiguation>American soul artist</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="2f727018-1e83-4797-8433-32c8b99dd057" type="Person" ext:score="94">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<gender>male</gender>
<country>GB</country>
<area id="8a754a16-0027-3a29-b6d7-2b40ea0481ed">
<name>United Kingdom</name>
<sort-name>United Kingdom</sort-name>
</area>
<disambiguation>of Maxïmo Park</disambiguation>
<life-span>
<begin>1979-03-13</begin>
<ended>false</ended>
</life-span>
</artist>
<artist id="e44ae2fa-9367-4691-bdb7-d097446ee3ce" type="Person" ext:score="94">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<disambiguation>Gabba/Acid techno artist</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="32c7cf45-867e-4076-a24c-ba38dccaa7bd" type="Person" ext:score="94">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<country>US</country>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
</area>
<disambiguation>American folk artist</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="bb57b210-bf27-4af1-8561-600f131bfc81" type="Person" ext:score="94">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<disambiguation>drum n bass producer aka Spinback</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="35287ce6-2fd4-41af-9248-d07e84eeb0df" type="Person" ext:score="94">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<disambiguation>Contemporary Christian artist peformed with The Imperials</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="6ece7fa3-c397-48a6-99f7-05e900b73d81" type="Person" ext:score="82">
<name>Nicholas Paul Smith</name>
<sort-name>Smith, Nicholas Paul</sort-name>
<gender>male</gender>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="3c1fbcf7-4bb8-49ac-8d35-3f4ee8b71e0a" type="Person" ext:score="79">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<gender>male</gender>
<country>US</country>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
</area>
<disambiguation>recording engineer, David "Honeyboy" Edwards recordings</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="24e472f9-6003-4873-aac5-c79763105a51" type="Person" ext:score="79">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<gender>male</gender>
<country>GB</country>
<area id="8a754a16-0027-3a29-b6d7-2b40ea0481ed">
<name>United Kingdom</name>
<sort-name>United Kingdom</sort-name>
</area>
<disambiguation>UK drummer</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="662c9cd6-73e2-426f-8e76-a8f2a8233215" type="Person" ext:score="79">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<country>AU</country>
<area id="106e0bec-b638-3b37-b731-f53d507dc00e">
<name>Australia</name>
<sort-name>Australia</sort-name>
</area>
<disambiguation>Australian bassist for Laughing Clowns/Ed Kuepper</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="0e911646-290a-4345-b3dc-e5ca91faaf88" type="Person" ext:score="79">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<gender>male</gender>
<country>GB</country>
<area id="8a754a16-0027-3a29-b6d7-2b40ea0481ed">
<name>United Kingdom</name>
<sort-name>United Kingdom</sort-name>
</area>
<disambiguation>British a cappella singer</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="75ffe808-187a-4488-8c84-7467efa2b277" type="Person" ext:score="79">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<disambiguation>of Dengue Fever</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="79d145cb-d862-487d-a340-b723a7c8eb26" type="Person" ext:score="79">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<country>GB</country>
<area id="8a754a16-0027-3a29-b6d7-2b40ea0481ed">
<name>United Kingdom</name>
<sort-name>United Kingdom</sort-name>
</area>
<disambiguation>Scottish electronic artist performing as Reverbaphon</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="1f483d17-7510-44d1-95a7-8c16c53c57a1" type="Person" ext:score="79">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<country>US</country>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
</area>
<disambiguation>US underground hip hop MC Breeze Brewin, of Weatherman, Def Jux</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="76e04e2a-e440-4729-8036-59928521c677" type="Person" ext:score="79">
<name>Paul Smith</name>
<sort-name>Smith, Paul</sort-name>
<gender>male</gender>
<country>US</country>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
</area>
<disambiguation>sound engineer, Randy Crawford & Joe Sample recordings</disambiguation>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="7a81a64e-4fdc-44a8-b33b-a447c611cf33" type="Group" ext:score="76">
<name>The Paul Smith Trio</name>
<sort-name>Paul Smith Trio, The</sort-name>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="7b458c24-ce5b-4b77-a1dc-616ff53d1e70" type="Group" ext:score="76">
<name>The Paul Smith Quartet</name>
<sort-name>Paul Smith Quartet, The</sort-name>
<country>US</country>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
</area>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="1c86fcf3-b56c-4427-856b-344d898abc33" ext:score="76">
<name>Paul Gerard Smith</name>
<sort-name>Smith, Paul Gerard</sort-name>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="e5fcb860-3210-4721-a44f-7bd3dcb4b5d5" ext:score="76">
<name>Paul Joseph Smith</name>
<sort-name>Paul Joseph Smith</sort-name>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="3eedd38b-f7ca-43d2-b635-adc4ad95371b" type="Person" ext:score="74">
<name>Margaret Thatcher</name>
<sort-name>Thatcher, Margaret</sort-name>
<gender>female</gender>
<country>GB</country>
<area id="8a754a16-0027-3a29-b6d7-2b40ea0481ed">
<name>United Kingdom</name>
<sort-name>United Kingdom</sort-name>
</area>
<life-span>
<begin>1925-10-13</begin>
<end>2013-04-08</end>
<ended>true</ended>
</life-span>
<tag-list>
<tag count="1">
<name>politician</name>
</tag>
<tag count="1">
<name>non-musician</name>
</tag>
</tag-list>
</artist>
<artist id="646c86db-d0af-403e-bef9-3deafd9c3d43" type="Person" ext:score="74">
<name>Brad Thatcher</name>
<sort-name>Thatcher, Brad</sort-name>
<life-span>
<ended>false</ended>
</life-span>
</artist>
<artist id="b5425c52-3e9c-4144-9467-eaa4d69389b8" type="Person" ext:score="74">
<name>Jim Thatcher</name>
<sort-name>Thatcher, Jim</sort-name>
<life-span>
<ended>false</ended>
</life-span>
<alias-list>
<alias sort-name="Thatcher, James" type="Legal name">James Thatcher</alias>
</alias-list>
</artist>
</artist-list>
</metadata>
<!doctype html>
<html>
<head>
<body>
<meta charset="utf-8">
<title>XML: Descrizione, Immagine, Link a Discogs</title>
</head>
<body>
<?php
$bb = "Paul Thatcher Smith"; //Example.
$name = strtolower(str_replace(" ","%20",$bb)); //all whitespaces must be coded with %20
$html = "http://musicbrainz.org/ws/2/artist/?query=".$name;
if (($response_xml_data = file_get_contents($html))===false){
echo "Error fetching XML\n";
}
else {
libxml_use_internal_errors(true);
$data = new SimpleXmlElement($response_xml_data); //all ok, you can do an echo, xml is well formed
$data->registerXPathNamespace('c',$html); //according to w3s
if (!$data) { //always have this error -.-
echo "Error loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
else {
$xpath='//c:artist'; //simple xpath query, if i put //* it gives me all xml
print_r($result = $data->xpath($xpath));
foreach ($result as $artist){
echo $artist . "<br>";
}
}
}
?>
最佳答案
此行不正确:
$data->registerXPathNamespace('c',$html);
$html
是您正在查询的 URL,但在这一行中,您需要指定您正在使用的 XML 的命名空间。该命名空间是:
http://musicbrainz.org/ns/mmd-2.0#
$data->registerXPathNamespace('c','http://musicbrainz.org/ns/mmd-2.0#');
关于php - 在php中使用Xpath,返回一个空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28281796/
编辑:为什么这被否决了?我真的不知道...顺便说一句 ../不起作用,因为我不想要 Table 的父级但实际上想要 ../td+1 我不知道这是否可能? 嗨,大家好。 我手头有一个相当复杂的问题..
我很难找到需要单击的输入(复选框)元素的 xpath。我正在尝试使用其他跨度元素来定位它。元素包含 Angular 属性,不知道这是否重要? 元素的结构如下: Company name
我正在尝试构建一个包含许多 XPath 作为参数的 DSL。我是 XPath 的新手,我需要一个 XPath 语法中从未使用过的字符,这样我就可以在脚本的一行中分隔 n 个 XPath。我的问题:哪些
使用xpath在父标签内找到特定标签: 输入样例:
我需要构造一个通用XPath来找到正确的节点,其中的标准是日期和时间。例如查找“ 5 May”,“ 12:17:44”的节点 XML具有日期和时间标签。 不方便地,日期标签仅在当天的第一次出现时填充。
我正在尝试获取xPath几个月内两个日期之间的差异。 几天之内我就没问题了(1127) days-from-duration(xs:date('2012-06-17')-xs:date('2009-0
我试图选择一个包含一段文本的元素,但是我不想选择包含该文本加上其他文本的元素。我通常会使用text()='abc def',但是这个特定元素在前后都包含空格。 这是一个示例片段:
亲爱的,您能帮我用这个XPATH吗?可以说我有以下HTML代码 text value1 value2 text 我需要构建一
我正在尝试提取带有排除项的 xpath,但无法执行此操作。 (//div[@class='row site country-names']/following-sibling::div)[1]/di
response.xpath('//*[@id="blah"]//text()') 假设我的html是 This is a simple text foo and this is after tag.
除了那些具有"//ul/li[not(@*)][count(*)=0]"父项的人以外,我需要全部接受。我已经尝试过,但是不幸的是它不起作用。 有谁知道,我该怎么处理? 提前致谢。 最佳答案 我认为您需
我使用XPath的问题是,每当我使用“子字符串”功能时,我只会得到一个匹配项,而我想全部获得它们。 另一个问题是,每当我使用“子字符串”和运算符的组合时它只是行不通(没有匹配项)。 例如:http:/
我正在尝试通过其位置和属性获取项目,但不知道如何做。 我要实现的是将这一点统一起来: Xpath("//h4/a[contains(@href,'#vuln_')]") 还有这个: Xpath
我有一个xpath如下: .//*[text()='Name:']/../child::select | .//*[text()='Name:']/../child::span 但是对我来说,它既不紧
我拼命试图在xpath中组合几个过滤器。假设我的数据如下所示: DELETE 1 This is my title my sh
我想在已经通过 xpath 设置的其他元素中使用 xpath 来指示元素的位置。 下面的一个已经通过 xpath 设置(我没有改变) //Base_Code
是否可以使用xpath直接在括号内抓取信息?还是以后再用正则表达式过滤? HTML如下所示: Product name (UN1QU3 C0D3) 使用以下Xpath表达式,我可以在此中获取所有内容:
我试图使用一个XPath表达式来选择一个节点,该节点的子节点与文档中的另一个节点匹配。 匹配将意味着该节点的所有属性都相同。因此,如果将一个节点与多个属性进行比较,则无法进行单独的属性比较。 作为示例
我想在 XPath 表达式中使用 Iverson 括号(即映射 true => 1,false => 0)。 示例:而不是书写 someNumber+(if(elem1/elem2[@attr='12
是否可以以类似方式选择节点? './tr[position() in (1, 3, 7)]' 我只找到以下解决方案: './tr[position() = 1 or position() = 3 or
我是一名优秀的程序员,十分优秀!