2 Replies Latest reply on Nov 19, 2009 8:13 AM by jsiggia

    update xml file

    jsiggia

      i am trying to create a senario in my xml doc where there can be many <forpage> entries for each message. the following loop creates incomplete entries

      in <forpage> see below.

       

           //convert list of <forpage> to an array for looping below

           <cfset myArrayList = ListToArray(opt)>

       

         <cfset arrayInsertAt(xApps.messageList.xmlChildren,1,xmlElemNew(xApps,'message'))>
         <cfset xApps.messageList.message[1].sender = xmlElemNew(xApps,'sender')>
         <cfset xApps.messageList.message[1].sender.xmlText = "#send#">
         <cfset xApps.messageList.message[1].creator = xmlElemNew(xApps,'creator')>
         <cfset xApps.messageList.message[1].creator.xmlText = "#creat#">

      //the loop attempts to enter multipe entries for <forpage>. <forpage> is converted from a list to an array

       

          <cfloop from="1" to="#arraylen(myArrayList)#" index="j">
                 <cfset arrayInsertAt(xApps.messageList.message.xmlChildren, j,xmlElemNew(xApps,'forPage'))>
                 <cfset xApps.messageList.message[1].forPage = xmlElemNew(xApps,'forPage')>
                 <cfset xApps.messageList.message[1].forPage.xmlText= "#myArrayList[j]#">  

           </cfloop>

       

      this code produces the following entry in my xml doc

       

      <messageList>
           <message>
                <sender>jljkjlkjlkj</sender>
                <forPage/><forPage/>
                <creator>lkjlkjljlkjklj</creator>
                <forPage>three</forPage>
           </message>

      </messagelist>

       

      any thoughts would be appreciated. thank you for your time

        • 1. Re: update xml file
          ilssac Level 5

          I am not sure what results you are trying to receive.

           

          But I'm gussing that somehow or the other you want different values so the only guess I can make is to add an array index to the forPage elements.

              <cfloop from="1" to="#arraylen(myArrayList)#" index="j">
                     <cfset arrayInsertAt(xApps.messageList.message.xmlChildren, j,xmlElemNew(xApps,'forPage'))>
                     <!--- <cfset xApps.messageList.message[1].forPage[j] = xmlElemNew(xApps,'forPage')> I beleive this line is redundant --->
                     <cfset xApps.messageList.message[1].forPage[j].xmlText= "#myArrayList[j]#">  
               </cfloop>
          
          • 2. Re: update xml file
            jsiggia Level 1

            yes that worked. i should of saved

            my old code because i tried something similiar to that. below is what i was shooting for. thanks for your time

             

            <messageList>
                 <message>
                      <forPage> abc application </forPage>
                      <forPage> intranet </forPage>
                      <forPage> home </forPage>
                      <sender>john</sender>
                      <creator>bob</creator>

                 </message>

            </messagelist>