r - 将 xml 文件差异转换为图形可视化
问题描述
我有两个具有结构的列表,并且希望将结构差异呈现为层次结构或图形,并且如果值存在差异,则还可以将具有相同结构的元素的值差异呈现。我是否需要展平两个列表并逐个元素进行比较,然后将 relist 与逐个元素的差异一起使用来创建一个结构化的差异列表以发送到渲染包?或者有捷径吗?我对渲染两个列表之间不常见的结构以及存在价值差异的常见结构感兴趣。到目前为止的代码
library(XML)
library(plyr)
f1="sample1.xml"
f2="sample2.xml"
skel1=xmlToList(f1,simplify=TRUE)
skel2=xmlToList(f2,simplify=TRUE)
unlistf1=unlist(skel1)
unlistf2=unlist(skel2)
f1NOTf2=!((unlistf1) %in% (unlistf2)) #value and structure differnce combined
f2NOTf1=!((unlistf2) %in% (unlistf1))
strf1NOTf2=!(names(unlistf1) %in% names(unlistf2)) # structural difference only
strf2NOTf1=!(names(unlistf2) %in% names(unlistf1))
listf1NOTf2=relist(f1NOTf2,skel1)
listf2NOTf1=relist(f2NOTf1,skel2)
strlistf1NOTf2=relist(strf1NOTf2,skel1)
strlistf2NOTf1=relist(strf2NOTf1,skel2)
sample1.xml 和 sample2.xml 下面
<?xml version="1.0"?>
<data>
<country xmlns="http://auto.org/schema/r4.0" name="Liechtenstein">
<rank>-1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<mountain name = "Himalaya"/>
<country name="Singapore">
<size name="small" />
<Temp>Hot</Temp>
<rank>4</rank>
<year>2015</year>
<gdppc>69900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama">
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
<country name="Japan">
</country>
</data>
<?xml version="1.0"?>
<data>
<country name="liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100 </gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapora" color="Green">
<rank>40</rank>
<gdppc>59900<free>TRUE</free></gdppc>
<neighbor name="Malaysia" direction="N"/>
<year>2011</year>
</country>
<country name="Panama">
<rank>100</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
解决方案
推荐阅读
- mysql - 按日期和其他列计算最后一个条目
- c# - 将动态类型传递给抽象覆盖方法
- amazon-web-services - 如何使用 spark 读取 Amazon SQS
- azure - Azure:如何为另一个租户中的应用注册创建 SQL 外部用户?
- r - R - 如何从字符向量中删除重复的字符串
- spring-boot - Spring Boot 需要 spring-boot-starter-security 作为 ssl 的依赖项
- database - Clickhouse - 添加一个新列,默认值基于另一列
- c++ - “此库现在需要 C++11 或更高版本的编译器...”在编译 boost 库的“number_base.hpp”时
- javascript - 如何在jQuery的依赖下拉列表中获取选定的值?
- ios - iOS 15 中的 CoreData + CloudKit 编译问题