2 Replies Latest reply on Jun 28, 2015 6:23 AM by Liphou

    [JS] Modification XML en E4X

    Liphou Level 1

      Hello, I would like to change the text " 888-555-2121 " as a selection with the value of the attribute but I does not succeed

      Here is a test code:


      var customer = <customer>

          <phone type="mobile">888-555-1212</phone>

          <phone type="office">888-555-2121</phone>

          <preferred>mobile</preferred>

      </customer> ;

       

       

      $.writeln (customer.phone.(@type == "office"));

       

      I would like to put " 666-333-4215 " instead " 888-555-2121 " by selecting the item "phone" with its attribute " type == 'office' "

      Je voudrais avec mettre "666-333-4215" à la place "888-555-2121" en sélectionnant l'élément "phone" grâce à son attribut "Type =='office'"

       

      thank you a lot

        • 1. Re: [JS] Modification XML en E4X
          TᴀW Adobe Community Professional & MVP

          Try this:

           

          var customers = <customers/>;
          
          
          var x = <customer>
              <phone type="mobile">first mobile</phone>
              <phone type="office">first office</phone>
              <preferred>mobile</preferred>
          </customer>
          
          
          customers.appendChild(x);
          
          
          var x = <customer>
              <phone type="mobile">second mobile</phone>
              <phone type="office">second office</phone>
              <preferred>mobile</preferred>
          </customer> ;
          
          
          customers.appendChild(x);
          
          
          alert(customers.customer.phone.(@type == "mobile"))
          
          
          customers.customer.phone.(@type == "mobile")[1] = "new number";
          
          
          alert(customers.customer.phone.(@type == "mobile"))
          
          

           

           

          The main point being that you need an index (like the index of an array) to point to the particular XML entry you want to modify. The first alert shows that there are 2 matching entries. Line 27 modifies one of them (the second). The second alert shows that the second has been modified.

          • 2. Re: [JS] Modification XML en E4X
            Liphou Level 1

            Thank you for opening my mind , it makes sense in the handling of XML to work with lists not knowing the number of elements .

            thank you


            Traduction Google du français vers l'anglais

            Merci de m'avoir ouvert l'esprit, il est logique dans la manipulation de donner XML de travailler avec des listes ne sachant pas le nombre d'éléments.

             

            Merci