• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

update xml file

New Here ,
Nov 19, 2009 Nov 19, 2009

Copy link to clipboard

Copied

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

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

TOPICS
Advanced techniques

Views

347

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 19, 2009 Nov 19, 2009

Copy link to clipboard

Copied

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 = xmlElemNew(xApps,'forPage')> I beleive this line is redundant --->
           <cfset xApps.messageList.message[1].forPage.xmlText= "#myArrayList#"> 
     </cfloop>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 19, 2009 Nov 19, 2009

Copy link to clipboard

Copied

LATEST

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation