Solr如何使用dataimportHandler从XML获取属性值

时间:2012-04-19 13:50:36

标签: xml solr lucene dataimporthandler

我需要从提供XML的HTTP Web服务中提取信息,如下所示:

<results>
<parametros>
    <param name="mode">xml</param>
</parametros>
<estacions>
    <estacio id="72400" nom="Aeroport"/>
    <estacio id="79600" nom="Arenys de Mar"/>
    <estacio id="79404" nom="Badalona"/>
    ...
</estacions>
</results>

如何获取属性值?例如id和nom属性? 这是我的dataconfig文件,但我没有看到如何实现这种情况。

<dataConfig>
    <dataSource type="HttpDataSource" />
    <document>
            <entity name="slashdot"
                    pk="link"
                    url=http://_host_/xmlservice/"
                    processor="XPathEntityProcessor"
                    forEach="/estacions"
                    transformer="DateFormatTransformer">
                    <field column="idestacio"       xpath="/estacio.id"   commonField="true" />
                    <field column="nomestacio"      xpath="/estacio.nom"    commonField="true" />                        
            </entity>
    </document>
</dataConfig> 

2 个答案:

答案 0 :(得分:0)

请参阅here如何使用JavaScript转换器来处理使用XPath提取的值。

答案 1 :(得分:0)

检索属性的xpath将是:

<field column="idestacio" xpath="/estacions/estacio/@id" commonField="true" />

xpath的一个很好的教程是:http://zvon.org/comp/r/tut-XPath_1.html#Pages~Attributes

相关问题