-1

在快速矿工中,我尝试使用 xpath 从 xml 页面获取数据,我尝试了许多不同的语句,但没有成功。下面是我试图检索的数据,我想要无序列表中的所有特征。

enter code here

<div id="features">
<h3>Features:</h3>
<ul><li>Front  garden</li>
<li>Rear Large Shed</li>
<li>Superb condition and tastefully decorated</li>
<li>Energy Efficent with a B2 Ber rating</li>
<li>Gravel &amp; driveway</li>
</ul></div>
4

2 回答 2

0

Assuming you want a sequence of strings there is the quick way:

//li/string()

And the specific way:

/div[@id='features']/ul/li/string()
于 2013-03-04T22:36:09.130 回答
0

您并没有真正指定您需要如何提取这些数据或它的去向,但也许这会有所帮助:

我将您的示例 xml 保存如下:

<?xml version="1.0" encoding="utf-8" ?>
<div id="features"> 
<h3>Features:</h3>
<ul><li>Front  garden</li>
<li>Rear Large Shed</li>
<li>Superb condition and tastefully decorated</li>
<li>Energy Efficent with a B2 Ber rating</li>
<li>Gravel &amp; driveway</li>
</ul></div>

然后,我创建了以下 RapidMiner 进程,该进程将每个列表元素作为单独的属性提取:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.005">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="5.3.005" expanded="true" name="Process">
    <process expanded="true">
      <operator activated="true" class="read_xml" compatibility="5.3.005" expanded="true" height="60" name="Read XML" width="90" x="112" y="165">
        <parameter key="file" value="path/to/Test.xml"/>
        <parameter key="xpath_for_examples" value="//h3"/>
        <enumeration key="xpaths_for_attributes">
          <parameter key="xpath_for_attribute" value="//li[1]/text()"/>
          <parameter key="xpath_for_attribute" value="//li[2]/text()"/>
          <parameter key="xpath_for_attribute" value="//li[3]/text()"/>
          <parameter key="xpath_for_attribute" value="//li[4]/text()"/>
          <parameter key="xpath_for_attribute" value="//li[5]/text()"/>
        </enumeration>
        <list key="namespaces"/>
        <parameter key="use_default_namespace" value="false"/>
        <list key="annotations"/>
        <list key="data_set_meta_data_information"/>
      </operator>
      <connect from_op="Read XML" from_port="output" to_port="result 1"/>
      <portSpacing port="source_input 1" spacing="0"/>
      <portSpacing port="sink_result 1" spacing="0"/>
      <portSpacing port="sink_result 2" spacing="0"/>
    </process>
  </operator>
</process>

我认为您要查找的 XPATH 查询是“//li[n]/text()”,其中 n 是您尝试从中提取数据的节点的编号。我希望这有帮助!

于 2013-03-07T04:45:52.347 回答