【发布时间】:2015-08-18 05:23:44
【问题描述】:
现有的 XML
<ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2013-08-01">
<OperationRequest>
<Arguments>xyz</Arguments>
</OperationRequest>
<Items>
<Item>
<ItemId>123<ItemId>
<CustomerReviews>
<IFrameURL>someurl</IFrameURL>
<HasReviews>true</HasReviews>
</CustomerReviews>
<EditorialReviews>
<Content>text</Content>
</EditorialReviews>
<Item>
</Items>
需要转换成
<ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2013-08-01">
<OperationRequest>
<Arguments>xyz</Arguments>
</OperationRequest>
<Items>
<Item>
<ItemId>123<ItemId>
<CustomerReviews>
<CustomerReview>
<ReviewText>abc<ReviewText>
<ReviewDate>May 24, 2015<ReviewDate>
</CustomerReview>
<CustomerReview>
<ReviewText>def<ReviewText>
<ReviewDate>June 24, 2014<ReviewDate>
</CustomerReview>
<HasReviews>true</HasReviews>
</CustomerReviews>
<EditorialReviews>
<Content>text</Content>
</EditorialReviews>
<Item>
</Items>
我能够删除 IFrameURL 并能够在 HasReviews 之前插入节点 CustomerReview,但是如何在 CustomerReview 中添加更多节点。 这是我迄今为止使用其他 Stack overflow post 所取得的成就。
<ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2013-08-01">
<OperationRequest>
<Arguments>xyz</Arguments>
</OperationRequest>
<Items>
<Item>
<ItemId>123<ItemId>
<CustomerReviews>
<CustomerReview>hello</CustomerReview>
<CustomerReview>hello</CustomerReview>
<CustomerReview>hello</CustomerReview>
<HasReviews>true</HasReviews>
</CustomerReviews>
<EditorialReviews>
<Content>text</Content>
</EditorialReviews>
<Item>
</Items>
PS:XML 结构末尾有 /ItemLookupResponse,但在代码中不可见。
【问题讨论】: