我有一个xml文件,如下所示。
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00000001</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>SCHAERER</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>REM</equipmentLocation>
<installedDate>2013-08-01T00:00:00.000+0000</installedDate>
</machineData>
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
现在我必须将2 xmls分成像
这样的数据1.XML
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00000001</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>SCHAERER</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>REM</equipmentLocation>
<installedDate>2013-08-01T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
2.XML
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
这必须在骡子中完成。在这种情况下请建议使用xslt。我是骡子的新人。
答案 0 :(得分:0)
将分割器与xpath MEL表达式结合使用:如下所示:
system.time({ temp_env <- new.env()
for(i in 1:length(x)){
y = x[i]
x1 = y*2
x2 = y*3
x3 = y*4
assign(paste0("obj", i), cbind(x1, x2, x3), envir = temp_env)
}
mydata_env <- do.call("rbind",
mget(paste0("obj", 1:length(x)), envir = temp_env))
})
user system elapsed
0.09 0.00 0.09
这将创建两个XML文档,如下所示:
<splitter expression="#[xpath('//machineDetail/machineData')]" doc:name="Splitter"/>
然后在拆分消息时使用XSLT或类似方法将XML包装在一个
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
元素
答案 1 :(得分:0)
以下流程应该按照您的要求进行。如果需要,您可能需要清理命名空间。
child threads