2013-03-04 51 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是您嘗試從中提取數據的節點的編號。我希望這有幫助!