Expand my Community achievements bar.

How to loop through all the nodes present in an embeded XML

Avatar

Level 9

Hello All,

I have a form which has embeded XML data. I would like to loop through all the nodes and delete all those nodes except one which is present in the original form. Let me explain.

Suppose I have a dropdown called ItemNumber. Basing upon the ItemNumber I have several other associated fields like ItemName,ItemCode,ItemPrice etc.

All these data are embeded in the form as XML.

Suppose the user selects ItemNumber- 30 ..And based upon that all the associated fields like ItemName 30, ItemCode30,ItemPrice30 are updated.

Now What I want is : I would like to loop through all the nodes present in the embeded xml and delete those nodes except node 30.

So that, when the user clicks the submit as xml only the node 30 data goes.

I hope I am clear in explaining what I want. Anybody here could help me on this ?? I am working under a deadline .Please help me .

Thanks.

Bibhu.

2 Replies

Avatar

Level 10

Bibhu,

        Here is a sample code for you to loop thru and identify the tags that are not needed and remove them from the XML before you submit.

        Let me know if you need more help/ explanation on this.

  

     

       //Remove the userImageURL tag from the Output XML

       var nodeToRemove
       for(i=0;i<xfa.datasets.data.nodes.length;i++){
             var strTagName = xfa.datasets.data.nodes.item(i).name;
           

             if(strTagName == "userImageURL"){
                      nodeToRemove = xfa.datasets.data.nodes.item(i);
                      xfa.datasets.data.nodes.remove(nodeToRemove); 
             }
        }

Thanks

Srini

Avatar

Level 9

Hello Srini,

Thanks for the reply. Let me explain what I mean.

Suppose my XML foes like this ..

<Customer>
<CustomerID>01ABCS</CustomerID>
<CustomerName>A</CustomerName>
<CustomerType>B</CustomerType>
<ContactName>C</ContactName>
<AddressLine3>D</AddressLine3>
<TelephoneNo>12345</TelephoneNo>
<ShipToCode>01</ShipToCode>
</Customer>

There are nearly 500 <customer> node. Suppose the user fills the form which is say node 20.My question is how to know from the field that the particular information correspond to which node ? And if we get to know that the information which is filled in the form corresponds to <customer> node 20 then we can delete all those nodes from the list and will submit the <customer > node 20 only. Please remember I can not delete all those attributes which are present in the <customer node > For ex : <CustomerID>, <CustomerName> etc. I hope I am clear while explaining it .

Thanks.

Bibhu.