<toplevel>
<CompleteSuggestion>
<suggestion data="shook ones part 2"/>
</CompleteSuggestion>
<CompleteSuggestion>
<suggestion data="shook me all night long"/>
</CompleteSuggestion>
<CompleteSuggestion>
<suggestion data="shook ones instrumental"/>
</CompleteSuggestion>
<CompleteSuggestion>
<suggestion data="shook me all night long lyrics"/>
</CompleteSuggestion>
</toplevel>
我想从这个XML输出中提取“shook ones part 2”。我已经完成了所有解决方案,但我无法做到这一点。 我试过这个:
<?php
$url = 'http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=shook&ds=yt';
$exact = simplexml_load_file($url);
echo $exact->CompleteSuggestion[0]->suggestion;
?>
答案 0 :(得分:1)
shook ones part 2
是data
的属性suggestion
的值。
因此,您应该获得suggestion
的所有属性attributes()
并选择data
:
$exact = simplexml_load_file('$url');
echo $exact->CompleteSuggestion[0]->suggestion->attributes()->data;
答案 1 :(得分:0)
忽略
中的单引号simplexml_load_file('$url');
^ ^
答案 2 :(得分:0)
您可以使用DOMDocumen t。下面的示例将搜索标记建议并回显数据属性:
private static object OnCoerceValue(DependencyObject d, object baseValue)
{
if (((DataGrid)d).HasItems)
{
DataGridRow row = ((DataGrid)d).ItemContainerGenerator.ContainerFromIndex(0) as DataGridRow;
if(row !=null)
{
if ((bool)baseValue)
{
FocusManager.SetIsFocusScope(row, true);
FocusManager.SetFocusedElement(row, row);
}
else if (((UIElement)d).IsFocused)
Keyboard.ClearFocus();
}
}
return ((bool)baseValue);
}