1

Existing 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>

Need to convert it to

<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>

I am able to remove IFrameURL and able to insert node CustomerReview before HasReviews, but how can I add more nodes inside CustomerReview. Here is what I have achieved till now using other 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 structure have /ItemLookupResponse at the end, but not visible in the code.

1 Answer 1

0

After spending a whole day, I figured it out.

Here is the link W3Schools, I used to get the work done. The minor difference is, use item(index) function to access particular array position. For e.g. The third line in the below code can be replaced with x=xmlDoc.getElementsByTagName("book").item(0); while using DOM java.

xmlDoc=loadXMLDoc("books.xml");
newel=xmlDoc.createElement("edition");
x=xmlDoc.getElementsByTagName("book")[0];
x.appendChild(newel);

Same goes for other functionalities.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.