Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Nokogiri的XML命名空间问题_Ruby_Nokogiri - Fatal编程技术网

Ruby Nokogiri的XML命名空间问题

Ruby Nokogiri的XML命名空间问题,ruby,nokogiri,Ruby,Nokogiri,我有以下XML: <body> <hello xmlns='http://...'> <world>yes</world> </hello> </body> 对 当我将其加载到Nokogiri XML文档中并调用document.at_css“world”时,我会收到nil返回。但是,当我删除hello的名称空间时,它工作得非常好。我知道我可以调用document.remove\u名称空间,但为什么它

我有以下XML:

<body>
  <hello xmlns='http://...'>
     <world>yes</world>
  </hello>
</body>

当我将其加载到Nokogiri XML文档中并调用
document.at_css“world”
时,我会收到
nil
返回。但是,当我删除
hello
的名称空间时,它工作得非常好。我知道我可以调用
document.remove\u名称空间,但为什么它不能与名称空间一起工作?

因为Nokogiri要求您注册要在其中查询的XML名称空间(请阅读更多信息)。但是,如果在调用
at_css
时指定了元素的名称空间,则仍然可以查询该元素。要查看确切用法,请查看。结果应该是这样的:

document.at_css "world", 'namespace_name' => 'namespace URI'

可能的重复是指
css
,而不是
xpath
。名称空间技术是相同的。不管你的查询是CSS还是XPath,谢谢你给我指出这个例子。您所做的不起作用,但在我包含名称空间管道时它起作用了:
document.at|css'ns | world',ns'=>'名称空间URI
值得注意的是,如果根元素上声明了名称空间,那么
#at#css
#css
方法将在查询中隐式包含名称空间。