在快速矿工中我试图从xml页面使用xpath获取数据,我尝试了许多不同的语句但没有成功。下面是我试图检索的数据,我想要无序列表中的所有功能。
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 & driveway</li>
</ul></div>
答案 0 :(得分:0)
假设你想要一系列字符串,那么就有了快捷的方法:
//li/string()
具体方式:
/div[@id='features']/ul/li/string()
答案 1 :(得分: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 & 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是您尝试从中提取数据的节点的编号。我希望这有帮助!