RT:
例如有下面这个xml文件,初始文件内容如下:
<TestService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<input>
<TestHeader>
<InterfaceCode>test</InterfaceCode>
<Operation>test1</Operation>
<AuthId>dfghsdfgsdf</AuthId>
</TestHeader>
<TestBody>
<list>
<ATPCheckReq>
<srcSys>1</srcSys>
<orderNo>2</orderNo>
<orderItemNo>3</orderItemNo>
</ATPCheckReq>
</list>
</TestBody>
</input>
</TestService>
当前xml中只有一组list,我想再增加一组或多组list,要求里面的字段相同,字段值不同,如何实现?
增加多组list后的xml文件内容如下:
<TestService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<input>
<TestHeader>
<InterfaceCode>test</InterfaceCode>
<Operation>test1</Operation>
<AuthId>dfghsdfgsdf</AuthId>
</TestHeader>
<TestBody>
<list>
<ATPCheckReq>
<srcSys>1</srcSys>
<orderNo>2</orderNo>
<orderItemNo>3</orderItemNo>
</ATPCheckReq>
</list>
<list>
<ATPCheckReq>
<srcSys>11</srcSys>
<orderNo>22</orderNo>
<orderItemNo>33</orderItemNo>
</ATPCheckReq>
</list>
<list>
<ATPCheckReq>
<srcSys>111</srcSys>
<orderNo>222</orderNo>
<orderItemNo>333</orderItemNo>
</ATPCheckReq>
</list>
</TestBody>
</input>
</TestService>
谢谢解答!
------解决方案--------------------
解析xml文件, 然后:
(1) 获取标签TestBody
(2)然后生成新的元素(element)
(3)将新生成的添加至TestBody标签中.
(4)最后重新输出xml