我在使用 xmlstarlet 使用第二个 xml 文件的数据更新 xml 文件时遇到了一些问题。例如,我有一个这种类型的第一个 xml 文件:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<timestamp></timestamp>
<results>
<idFile>1</dFile>
<activated>true</activated>
<id>9159820</id>
<content>
<resultDate>25/02/2018 19:33</resultDate>
<presDate>01/01/2018</prescriptionDate>
<seen>false</seen>
<prescriberName>BABA</prescriberName>
<labId>789</labId>
<labName>Bio</laName>
<checkedResults>
<id>177331580</id>
<localCode>GLU</localCode>
<localLabel>GLU</localLabel>
<Code>17856-6</Code>
<value>IN</value>
<unit>%</unit>
<normalLow>4.0</normalLow>
<normalHeight>6.0</normalHeight>
<Label>BABA</Label>
</checkedResults>
<checkedResults>
<id>177331580</id>
<localCode>GLU</localCode>
<localLabel>GLU</localLabel>
<Code>17856-6</Code>
<value>IN</value>
<unit>%</unit>
<normalLow>4.0</normalLow>
<normalHeight>6.0</normalHeight>
<Label>BABA</Label>
</checkedResults>
</content>
</results>
</root>
还有第二个文件
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<timestamp></timestamp>
<results>
<idFile>2</dFile>
<activated>true</activated>
<id>9159810</id>
<content>
<resultDate>25/02/2018 19:33</resultDate>
<presDate>01/01/2018</prescriptionDate>
<seen>false</seen>
<prescriberName>BABA</prescriberName>
<labId>789</labId>
<labName>Bio</laName>
<checkedResults>
<id>177331580</id>
<localCode>GLU</localCode>
<localLabel>GLU</localLabel>
<Code>17856-6</Code>
<value>IN</value>
<unit>%</unit>
<normalLow>4.0</normalLow>
<normalHeight>6.0</normalHeight>
<Label>BABA</Label>
</checkedResults>
<checkedResults>
<id>177331580</id>
<localCode>GLU</localCode>
<localLabel>GLU</localLabel>
<Code>17856-6</Code>
<value>IN</value>
<unit>%</unit>
<normalLow>4.0</normalLow>
<normalHeight>6.0</normalHeight>
<Label>BABA</Label>
</checkedResults>
</content>
</results>
</root>
我想要的是这样的(我只需要用第二个文件的元素结果更新(添加)第一个文件):
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<timestamp></timestamp>
<results>
<idFile>1</dFile>
<activated>true</activated>
<id>9159810</id>
<content>
<resultDate>25/02/2018 19:33</resultDate>
<presDate>01/01/2018</prescriptionDate>
<seen>false</seen>
<prescriberName>BABA</prescriberName>
<labId>789</labId>
<labName>Bio</laName>
<checkedResults>
<id>177331580</id>
<localCode>GLU</localCode>
<localLabel>GLU</localLabel>
<Code>17856-6</Code>
<value>IN</value>
<unit>%</unit>
<normalLow>4.0</normalLow>
<normalHeight>6.0</normalHeight>
<Label>BABA</Label>
</checkedResults>
<checkedResults>
<id>177331580</id>
<localCode>GLU</localCode>
<localLabel>GLU</localLabel>
<Code>17856-6</Code>
<value>IN</value>
<unit>%</unit>
<normalLow>4.0</normalLow>
<normalHeight>6.0</normalHeight>
<Label>BABA</Label>
</checkedResults>
</content>
</results>
<results>
<idFile>2</dFile>
<activated>true</activated>
<id>9159810</id>
<content>
<resultDate>25/02/2018 19:33</resultDate>
<presDate>01/01/2018</prescriptionDate>
<seen>false</seen>
<prescriberName>BABA</prescriberName>
<labId>789</labId>
<labName>Bio</laName>
<checkedResults>
<id>177331580</id>
<localCode>GLU</localCode>
<localLabel>GLU</localLabel>
<Code>17856-6</Code>
<value>IN</value>
<unit>%</unit>
<normalLow>4.0</normalLow>
<normalHeight>6.0</normalHeight>
<Label>BABA</Label>
</checkedResults>
<checkedResults>
<id>177331580</id>
<localCode>GLU</localCode>
<localLabel>GLU</localLabel>
<Code>17856-6</Code>
<value>IN</value>
<unit>%</unit>
<normalLow>4.0</normalLow>
<normalHeight>6.0</normalHeight>
<Label>BABA</Label>
</checkedResults>
</content>
</results>
</root>
到目前为止我所尝试的:
使用命令xmlstarlet ed 1.xml 2.xml > 3.xml
但是这个命令只是将两个文件合并为一个具有相同标题的文件。你有什么想法可以指导我解决这个问题吗?