2013-03-04 59 views
-1

在快速矿工中,我试图从xml页面使用xpath获取数据,我尝试了一些不同的语句,但没有成功。下面是即时通讯尝试检索的数据,我想要从无序列表中获取所有功能。快速矿工的apath声明

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> 

回答

0

假设你想串序列存在的快捷方式:

//li/string() 

和具体方式:

/div[@id='features']/ul/li/string() 
+0

我已经尝试了这两个语句,但我得到相同的错误回读说规定的xpath查询无效,预期节点类型。我已经用文本替换了字符串,并且该过程将运行,但dosent返回任何值。请帮助 – user2133572 2013-03-05 22:02:10

+0

@ user2133572您能提供一个更大的代码片段来展示您正在做什么吗? xpath是有效的,所以它可能是执行xpath的调用者函数中的一些东西。 – wst 2013-03-06 04:52:09

+0

@ user2133572将代码片段放在您的问题中。它看起来像你试图编辑我的答案,并且更改被mods拒绝。 – wst 2013-03-06 16:10:57

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查询“//李[N] /文()“其中n是您尝试从中提取数据的节点的编号。我希望这有帮助!