【问题标题】:Solr How can i get the attribute values from XML using dataimportHandlerSolr 如何使用 dataimportHandler 从 XML 获取属性值
【发布时间】:2012-04-19 13:50:35
【问题描述】:

我需要从服务 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> 

【问题讨论】:

    标签: xml solr lucene dataimporthandler


    【解决方案1】:

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

    【讨论】:

    【解决方案2】:

    检索属性的 xpath 将是:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      • 2013-06-18
      相关资源
      最近更新 更多