<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1012617" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1012617</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/writing-xml-data-user-provided-file#comment-1073037</link>
    <description> &lt;p&gt;Unfortunately I haven&#039;t much experience at XML..to be precise .. just about NULL experience. However if I am grasping the concept of your problem, you just want to write the XML text to a file. If that is so, this little code would do exactly what I think you want. &lt;/p&gt;
&lt;p&gt;############## COPY CODE BELOW #################&lt;/p&gt;
&lt;p&gt;#!/usr/bin/perl&lt;/p&gt;
&lt;p&gt;&amp;amp;Parse_Form;                      # puts the input in a hash&lt;br /&gt;
$file = $formdata{&#039;xmlfn&#039;}         # user specified file&lt;br /&gt;
$xmldata = $formdata{&#039;xmldata&#039;};  # inputed xml data&lt;/p&gt;
&lt;p&gt;# open text file change the extension if you don&#039;t want txt&lt;br /&gt;
open (FILE, &quot;&amp;gt; ../$file.txt&quot;) || &amp;amp;error(&#039;file open error&#039;);&lt;br /&gt;
flock(FILE, 2);                   # lock the file&lt;br /&gt;
print FILE &quot;$xmldata&quot;;            # print the xmldata to file&lt;br /&gt;
flock(FILE, 8);                   # unlock the file&lt;br /&gt;
close (FILE);                     # close the file&lt;/p&gt;
&lt;p&gt;print &quot;Content-type:text/html\n\n&quot;; # mime type&lt;br /&gt;
print &quot;Done&quot;;                     # so it won&#039;t error with no content&lt;br /&gt;
exit;&lt;/p&gt;
&lt;p&gt;# Parser subroutine : use either post or get&lt;br /&gt;
sub Parse_Form {&lt;br /&gt;
	if ($ENV{&#039;REQUEST_METHOD&#039;} eq &#039;GET&#039;) {&lt;br /&gt;
		@pairs = split(/&amp;amp;/, $ENV{&#039;QUERY_STRING&#039;});&lt;br /&gt;
	} elsif ($ENV{&#039;REQUEST_METHOD&#039;} eq &#039;POST&#039;) {&lt;br /&gt;
		read (STDIN, $buffer, $ENV{&#039;CONTENT_LENGTH&#039;});&lt;br /&gt;
		@pairs = split(/&amp;amp;/, $buffer);&lt;/p&gt;
&lt;p&gt;		if ($ENV{&#039;QUERY_STRING&#039;}) {&lt;br /&gt;
			@getpairs =split(/&amp;amp;/, $ENV{&#039;QUERY_STRING&#039;});&lt;br /&gt;
			push(@pairs,@getpairs);&lt;br /&gt;
			}&lt;br /&gt;
	} else {&lt;br /&gt;
		print &quot;Content-type: text/html\n\n&quot;;&lt;br /&gt;
		print &quot;Use Post or Get&quot;;&lt;br /&gt;
	}&lt;/p&gt;
&lt;p&gt;	foreach $pair (@pairs) {&lt;br /&gt;
		($key, $value) = split (/=/, $pair);&lt;br /&gt;
		$key =~ tr/+/ /;&lt;br /&gt;
		$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;&lt;br /&gt;
		$value =~ tr/+/ /;&lt;br /&gt;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;&lt;/p&gt;
&lt;p&gt;		$value =~s///g;&lt;/p&gt;
&lt;p&gt;		if ($formdata{$key}) {&lt;br /&gt;
			$formdata{$key} .= &quot;, $value&quot;;&lt;br /&gt;
		} else {&lt;br /&gt;
			$formdata{$key} = $value;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;# Error Subroutine&lt;/p&gt;
&lt;p&gt;sub error {&lt;br /&gt;
print &quot;SORRY THERE WAS AN ERROR:$_[0];&quot;;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;######## END OF SCRIPT ########&lt;/p&gt;
&lt;p&gt;That little tidbit will take a user specified file from your form, and write the xml data to it. Make sure the permission are set correctly...755 for scripts...777 for text files.&lt;/p&gt;
&lt;p&gt;And don&#039;t forget to add a submit button to your form.&lt;/p&gt;
&lt;p&gt;Now may I ask for a favor? It appears that you have a grasp on XML...something I haven&#039;t had time to accomplish. Do you think you can brief me on some of XML&#039;s aspects? Perhaps a general tutoring session? Thanx.&lt;/p&gt;
&lt;p&gt;Hope that helps you out.&lt;/p&gt;
&lt;p&gt;[Edited by Ken Elliott on 10-19-2000 at 09:09 AM]&lt;/p&gt;
 </description>
     <pubDate>Thu, 19 Oct 2000 13:06:53 +0000</pubDate>
 <dc:creator>Ken Elliott</dc:creator>
 <guid isPermaLink="false">comment 1073037 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
