我的源 XML 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<MT_A2B>
<Header>
<ReceiverID>XYZ Pvt Ltd.</ReceiverID>
<Date>2013-05-16</Date>
<FileId>1</FileId>
<Version>1.0</Version>
</Header>
<Invoice>
<ItemsInfo>
<Item id="A1">
<AccountID>1234567890</AccountID>
<AccountName>657-6746-AM2</AccountName>
<AccountType>CONTRACT</AccountType>
<Type>/item/cxn/vpn/cycle</Type>
<Name>VPN cycle fees</Name>
<SessionCount>3</SessionCount>
<NetAmount>3000.00</NetAmount>
<Tot>
<UsageClass>AOC</UsageClass>
<SessionCount>3</SessionCount>
<Quantity>4</Quantity>
<FreeQuantity>1</FreeQuantity>
<NetAmount>3000.00</NetAmount>
<ZoneTot>
<ZoneDescription>To Category 2</ZoneDescription>
<GLID>300|A1000001|F1000001|50001</GLID>
<SetUpFee>0.00000</SetUpFee>
<Unit>1</Unit>
<UnitPrice>1000.0000</UnitPrice>
<SessionCount>2</SessionCount>
<Quantity>3</Quantity>
<FreeQuantity>1</FreeQuantity>
<NetAmount>2000.00</NetAmount>
</ZoneTot>
<ZoneTot>
<ZoneDescription>To Category 2</ZoneDescription>
<GLID>300|A1000001|F1000001|50001</GLID>
<SetUpFee>0.00000</SetUpFee>
<Unit>1</Unit>
<UnitPrice>1000.0000</UnitPrice>
<SessionCount>1</SessionCount>
<Quantity>1</Quantity>
<FreeQuantity>0</FreeQuantity>
<NetAmount>1000.00</NetAmount>
</ZoneTot>
</Tot>
</Item>
</ItemsInfo>
</Invoice>
</MT_A2B>
我必须检查 Tot 节点是否有多个 ZoneTot。如果是,那么我必须再创建一个 Tot 节点来容纳第二个 ZoneTot 节点。基本上,每个 Tot 节点应该只有一个 ZoneTot 节点。如果 Tot 节点中有多个 ZoneTot 节点,那么我必须正确格式化它。我需要对第二个 Tot 节点中存在的字段进行一些计算,但我在这里没有提到它。我必须首先满足格式化 XML 的基本要求。
我希望输出 XML 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<MT_A2B>
<Header>
<ReceiverID>XYZ Pvt Ltd.</ReceiverID>
<Date>2013-05-16</Date>
<FileId>1</FileId>
<Version>1.0</Version>
</Header>
<Invoice>
<ItemsInfo>
<Item id="A1">
<AccountID>1234567890</AccountID>
<AccountName>657-6746-AM2</AccountName>
<AccountType>CONTRACT</AccountType>
<Type>/item/cxn/vpn/cycle</Type>
<Name>VPN cycle fees</Name>
<SessionCount>3</SessionCount>
<NetAmount>3000.00</NetAmount>
<Tot>
<UsageClass>AOC</UsageClass>
<SessionCount>3</SessionCount>
<Quantity>4</Quantity>
<FreeQuantity>1</FreeQuantity>
<NetAmount>3000.00</NetAmount>
<ZoneTot>
<ZoneDescription>To Category 2</ZoneDescription>
<GLID>300|A1000001|F1000001|50001</GLID>
<SetUpFee>0.00000</SetUpFee>
<Unit>1</Unit>
<UnitPrice>1000.0000</UnitPrice>
<SessionCount>2</SessionCount>
<Quantity>3</Quantity>
<FreeQuantity>1</FreeQuantity>
<NetAmount>2000.00</NetAmount>
</ZoneTot>
</Tot>
<Tot>
<UsageClass>AOC</UsageClass>
<SessionCount>3</SessionCount>
<Quantity>4</Quantity>
<FreeQuantity>1</FreeQuantity>
<NetAmount>3000.00</NetAmount>
<ZoneTot>
<ZoneDescription>To Category 2</ZoneDescription>
<GLID>300|A1000001|F1000001|50001</GLID>
<SetUpFee>0.00000</SetUpFee>
<Unit>1</Unit>
<UnitPrice>1000.0000</UnitPrice>
<SessionCount>1</SessionCount>
<Quantity>1</Quantity>
<FreeQuantity>0</FreeQuantity>
<NetAmount>1000.00</NetAmount>
</ZoneTot>
</Tot>
</Item>
</ItemsInfo>
</Invoice>
</MT_A2B>