Skip to main content
Participant
May 19, 2009
Question

Appending an xml file

  • May 19, 2009
  • 1 reply
  • 474 views

Hi,

I've created an xml document from a query and simply need after the document is created to append to this file so that each time the page is executed and I go to the directory where the file is stored, I can see all the submissions.  The code works fine (when its run the first time) but after that I keep getting a "Only one top level element is allowed in an XML document" error.  I've tried re-formatting the xml and playing with the attributes of the cffile tag to no avail.

Any thoughts??

Thanks in Advance

<CFOUERY NAME='qryGetResults" DATASOURCE="Kyo">

     Select school_id

     From tblSchool

     Where school_id = 13

</CFQUERY>

<!--Careate xml document object containing data-->

          <cfxml variable = "SchoolRec">

               <TrainingRequest>

                    <cfoutput query="qryGetResults">

                         <Required>

                              <school_num>#school_id#</school_num>

                              <school_name>#school_name#</school_name>

                         </Required>

                    </cfoutput>

               <TrainingRequest>

          </cfxml>

<cfset xmltext = ToString (SchoolRec)>

<cffile action="append" file="c:\Temp\School.xml" output="xmltext">

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    May 20, 2009

    You can't concatenate 2 xml documents (as strings) and get a new

    well-formed xml document and that is what you're doing here. You need

    to read the previously saved xml string from file, parse the string

    into an xml object, insert the new entries into their correct places

    in the xml hierarchy and then overwrite the previous file.

    Mack

    Participant
    May 20, 2009

    Got it, I'll go ahead and give it a try

    Thanks