Skip to main content
December 19, 2008
Question

Wrting to an XML file using Coldfusion

  • December 19, 2008
  • 1 reply
  • 661 views
Hi All,I need some help with .

I have an XML file like:

<Emp>
<Name></Name>
<City></City>
<State></State>
</Emp>

And one form , where I am trying to submit the form values which are as input fields and add or append the old xml content with the new content.So that the above file looks like:

<Emp>
<Name>Jack</Name>
<City>Jonney</City>
<State>New Jersey</State>
</Emp>
I have seen CFFIle but then it seems to be saving the whole XML file and here I want to just update specific elements.
Thanks in advance.
This topic has been closed for replies.

1 reply

Inspiring
December 19, 2008
jjonney wrote:
> I have seen CFFIle but then it seems to be saving the whole XML file and here
> I want to just update specific elements.
> Thanks in advance.
>

Thats the way it works. The usual process is to load the XML document,
use ColdFusion XML and|or string functions to modify the XML then write
out the file. This does present limits with very large XML files.

If you need something more refined, you need to dive into the Java
underpinnings that do allow for more granular processing of file data.
I can't provide any examples, but I'm sure Google can.
December 19, 2008
Hi .
Thanks for answering .It helped as I was trying to get it work and it just didn't work .
But there is something which is not right in the following code.
BKBK
Community Expert
Community Expert
December 21, 2008
You can do it in 4 lines, as shown below. Also watch out for the following:

1) Your XML has an error. The attribute must be within quotes, thus: <blog name="First">.
2) Just read the file as text and write it back as text. Don't add the function XMLParse. It could transform <itunessubtitle></itunessubtitle> into <itunessubtitle/> and append <?xml version="1.0" encoding="UTF-8"?>, resulting in a different document.