本文介绍了如何从XML表中获取表数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个xml文件,它有一些html内容,如粗体,段落和表格。我写了shell脚本来解析除表格以外的所有html标签。我正在使用XML(R包)解析数据。
<根>
<标题>这是虚拟xml文件< / Title>
<内容>此表格汇总了BMC格式的数据。
< div class =abctable>
< tbody>
< tr>
< th width =50%> ABC< / th>
< th width =50%>体重状态< / th>
< / tr>
< tr>
< td>是18.5< / td>
< td> arew< / td>
< / tr>
< tr>
< td> 18.5& amp; mdash; 24.9< / TD>
< td> rweq< / td>
< / tr>
< tr>
< td> 25.0& amp; mdash; 29.9< / TD>
< td> qewrte< / td>
< / tr>
< tr>
< td> 30.0和hwerqer< / td>
< td> rwqe< / td>
< / tr>
< tr>
< td> 40.0 rweq rweq< / td>
< td> rqwe reqw< / td>
< / tr>
< / tbody>
< / table>
< / div>
< / Content>
< Section>等等等等等等< / Section>
< / Root>
如何解析xml中这个表的内容?
$ b $在 XML 中有一个叫做 readHTMLTable
的函数。
以下是使用以下xml文件执行此操作的方法:
< Root>
<标题>这是虚拟xml文件< / Title>
<内容>
此表格汇总了BMC格式的数据。
< div class =abctable>
< tbody>
< tr>
< th width =50%> ABC< / th>< th width =50%> Weight status< / th>
< / tr>
< tr>
< td>是18.5< / td>
< td> arew< / td>
< / tr>
< tr>
< td> 18.5& amp; mdash; 24.9< / TD>
< td> rweq< / td>
< / tr>
< tr>
< td> 25.0& amp; mdash; 29.9< / TD>
< td> qewrte< / td>
< / tr>
< tr>
< td> 30.0和hwerqer< / td>
< td> rwqe< / td>
< / tr>
< tr>
< td> 40.0 rweq rweq< / td>
< td> rqwe reqw< / td>
< / tr>
< / tbody>
< / table>
< / Content>
< / div>
< Section>等等等等等等< / Section>
< / Root>
如果保存在名为 /tmp/data.xml
那么你可以使用下面的代码:
doc< - htmlParse(/ tmp / data。 xml)
tableNodes< - getNodeSet(doc,// table)
tb< - readHTMLTable(tableNodes [[1]])
/ pre>
哪五种:
R> tb
V1 V2
1 ABC体重状态
2是18.5 arew
3 18.5& mdash; 24.9美元
4 25.0& mdash; 29.9 qewrte
5 30.0 and hwerqer rwqe
6 40.0 rweq rweq rqwe reqw
I have one xml file which has some html content like bold, paragraph and tables. I have written shell script to parse all html tags except tables. I'm using XML (R package) to parse the data.
<Root>
<Title> This is dummy xml file </Title>
<Content> This table summarises data in BMC format.
<div class="abctable">
<table border="1" cellspacing="0" cellpadding="0" width="100%" class="coder">
<tbody>
<tr>
<th width="50%">ABC</th>
<th width="50%">Weight status</th>
</tr>
<tr>
<td>are 18.5</td>
<td>arew</td>
</tr>
<tr>
<td>18.5 &mdash; 24.9</td>
<td>rweq</td>
</tr>
<tr>
<td>25.0 &mdash; 29.9</td>
<td>qewrte</td>
</tr>
<tr>
<td>30.0 and hwerqer</td>
<td>rwqe</td>
</tr>
<tr>
<td>40.0 rweq rweq</td>
<td>rqwe reqw</td>
</tr>
</tbody>
</table>
</div>
</Content>
<Section>blah blah blah</Section>
</Root>
How to parse the content of this table which in present in xml?
解决方案 Well there is a function called readHTMLTable
in the XML
package, that seems to do just what you need ?
Here is a way to do it with the following xml file :
<Root>
<Title> This is dummy xml file </Title>
<Content>
This table summarises data in BMC format.
<div class="abctable">
<table border="1" cellspacing="0" cellpadding="0" width="100%" class="coder">
<tbody>
<tr>
<th width="50%">ABC</th><th width="50%">Weight status</th>
</tr>
<tr>
<td>are 18.5</td>
<td>arew</td>
</tr>
<tr>
<td>18.5 &mdash; 24.9</td>
<td>rweq</td>
</tr>
<tr>
<td>25.0 &mdash; 29.9</td>
<td>qewrte</td>
</tr>
<tr>
<td>30.0 and hwerqer</td>
<td>rwqe</td>
</tr>
<tr>
<td>40.0 rweq rweq</td>
<td>rqwe reqw</td>
</tr>
</tbody>
</table>
</Content>
</div>
<Section>blah blah blah</Section>
</Root>
If this is saved in a file called /tmp/data.xml
then you can use the following code :
doc <- htmlParse("/tmp/data.xml")
tableNodes <- getNodeSet(doc, "//table")
tb <- readHTMLTable(tableNodes[[1]])
Which fives :
R> tb
V1 V2
1 ABC Weight status
2 are 18.5 arew
3 18.5 — 24.9 rweq
4 25.0 — 29.9 qewrte
5 30.0 and hwerqer rwqe
6 40.0 rweq rweq rqwe reqw
这篇关于如何从XML表中获取表数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-26 09:20
-
strip_tags禁止一些标签
-
如何将关联数组作为参数传递给 Bash 中的函数?
-
为什么 go.Scatter 打印额外的行而 px.line 不是?
-
在这个 php 配置中是否启用了 mysqli 扩展?
-
angularjs:ng-repeat-start 和 ng-repeat-end 带有内部 ng-repeat
-
如何在 PHP 中更改 PDO/SQLite 连接的字符编码?
-
装饰设计师:尽我所能理解它
-
JavaScript获取样式
-
在 dom 完成渲染后如何运行指令?
-
在表单字段-Angular-ReactiveForms 中至少更改一个值之前,使用验证更新表单不起作用
-
在 <a> 中,ngclick 优先于 nghref元素
-
laravel如何将字段更新到数据库
-
在VB.net中观看MySQL表
-
MYSQL连接结果集在where子句中的IN()期间擦除了结果?
-
在下面的一个有效的base64连接codeD TIF图片的反应?
查看更多