English 中文(简体)
利用诺科吉里从该XML中提取“语言艺术家”需要什么?
原标题:What does it take to get the "LyricArtist" from this XML feed using Nokogiri?

First the xml: http://api.chartlyrics.com/apiv1.asmx//GetLyric?lyricId=90&lyricCheckSum=9600c891e35f602eb6e1605fb7b5229e

doc = Nokogiri::XML(open("http://api.chartlyrics.com/apiv1.asmx//GetLyric?lyricId=90&lyricCheckSum=9600c891e35f602eb6e1605fb7b5229e"))

成功将占用文件内容。

在这一点之后,我无法从中获取和收集 gr数据,我无法确定为什么?

例如,预计:

doc.xpath("//LyricArtist")

击退艺术家,但不是。

我曾尝试过其他饲料,如拖欠的RSS供暖,任何电压装置都提供,如果我做这样的事情:

doc.xpath("//link")

我收到了所有“链接”的清单。

我肯定没有东西,并热爱你们的投入。 感谢!

问题回答

XML要素是:名称空间的合格,并须遵守

如果你认为XML,你会注意到文件内容有了一个名称空间:

<GetLyricResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://api.chartlyrics.com/">

为了对一个名称空间具有约束力的要素进行匹配,你要么需要宣布一个名称空间,该名称空间受《国际仲裁裁决汇编》约束,在你XPATH的表述中使用该名称空间,要么使用XPATH的表述,要么忽视名称空间,要么不同。

无论已申报的名称空间如何,你都可以对内容进行匹配,然后使用<代码>当地名称()与元素名称匹配。

//*[local-name()= LyricArtist ]

如果你想更确切,你可以使用<代码>当地名称()与元素名称和<代码>,即:space-uri(,与已申报的地名空间相匹配。

//*[local-name()= LyricArtist  and namespace-uri()= http://api.chartlyrics.com/ ]

第二个例子将防止将受不同名称空间约束的相同<代码>当地名称/代码>的内容相匹配。 并非这一具体问题,而是你们应当知道的问题。 姓名空间被用于独一无二地限定节点,允许不同的词汇在不担心冲突的情况下使用相同的“名称”。

它就像在名称或图象上的东西。

uri = "http://api.chartlyrics.com/apiv1.asmx//GetLyric?LyricId=90&lyricCheckSum=9600c891e35f602eb6e1605fb7b5229e"
x = open(uri).read()
x = x.sub(/<.*?>/,  ).sub(/<.*?>/, <GetLyricResult> )
doc = Nokogiri::XML(x)
puts doc.xpath( //LyricArtist ).text()




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签