我试图使用Jython和ElementTree解析Google Refine中的一些xml,但我很难找到任何文档来帮助我实现这一点(可能不是python代码编写者也没有帮助)
这是我试图解析的XML的一个摘录。我试图返回所有dc:indentifier
的联接字符串:
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:creator>J. Koenig</dc:creator>
<dc:date>2010-01-13T15:47:38Z</dc:date>
<dc:date>2010-01-13T15:47:38Z</dc:date>
<dc:date>2010-01-13T15:47:38Z</dc:date>
<dc:identifier>CCTL0059</dc:identifier>
<dc:identifier>CCTL0059</dc:identifier>
<dc:identifier>http://open.jorum.ac.uk:80/xmlui/handle/123456789/335</dc:identifier>
<dc:format>application/pdf</dc:format>
</oai_dc:dc>
这是我目前掌握的密码。这是一个返回任何内容的测试,因为现在我得到的只是“Error:null”
^{pr2}$
以下是对J.F.Sebastian的版本稍作调整,可以直接粘贴到Google Refine中:
它返回一个逗号分隔的列表,但是您可以更改return语句中使用的分隔符。在
您使用了错误的命名空间。这适用于Jython 2.5.1:
输出
^{pr2}$你可以用这样的GREL表达式,试试看:
对于找到的每个标识符,给我htmlText并用逗号将它们连接起来。 parseHtml()使用Jsoup.org网站库,并真正解析标记和结构。它还知道如何使用ns | identifier格式解析名称空间,在这种情况下,它是一种很好的方法来获取您的后续内容。在
相关问题 更多 >
编程相关推荐