Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: Appending XML

Reply
Thread Tools

Re: Appending XML

 
 
Jim
Guest
Posts: n/a
 
      04-27-2006
I've tried using JScript and VBScript but I cant get it to work, I'm not
realy bothered what technology I use just as long as it works.

Heres how the XML looks

<data>
<record>
<email>(E-Mail Removed)</email>
<feedback>some feedback</feedback>
</record>
</data>

"Jim" <(E-Mail Removed)> wrote in message
news:juT3g.1640$(E-Mail Removed)...
> Could anyone please point me towards some code that allows me to add to an
> existing XML file using the output of an HTML form.
>
> I want to add a form on my website so users can input their email address
> in a text field and feedback in a text area and then submit it. I can
> output the data no probs but appending it first to the XML file is proving
> tricky.
>
> Any ideas?
>



 
Reply With Quote
 
 
 
 
Johannes Koch
Guest
Posts: n/a
 
      04-27-2006
> "Jim" <(E-Mail Removed)> wrote in message
> news:juT3g.1640$(E-Mail Removed)...
>
>>Could anyone please point me towards some code that allows me to add to an
>>existing XML file using the output of an HTML form.
>>
>>I want to add a form on my website so users can input their email address
>>in a text field and feedback in a text area and then submit it. I can
>>output the data no probs but appending it first to the XML file is proving
>>tricky.


Jim wrote:
> I've tried using JScript and VBScript but I cant get it to work, I'm
> not realy bothered what technology I use just as long as it works.
>
> Heres how the XML looks
>
> <data>
> <record>
> <email>(E-Mail Removed)</email>
> <feedback>some feedback</feedback>
> </record>
> </data>


1. DOM-parse your XML file, add a new record element, serialize the DOM
document.
or
2. Read your original XML file into a string, remove last line, add
string for the record element, add last line, save to file.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      04-27-2006
Jim wrote:
> I've tried using JScript and VBScript but I cant get it to work, I'm not
> realy bothered what technology I use just as long as it works.
>
> Heres how the XML looks
>
> <data>
> <record>
> <email>(E-Mail Removed)</email>
> <feedback>some feedback</feedback>
> </record>
> </data>


The following script does the job (copies all except the last
line of the file to a temporary file, appends the new elements,
adds back the data end-tag, and copies it all back to the
original file). If you want it to run as CGI, you'll need to
add the Content-Type and response HTML in the usual way and
address it as http://your.server.com/cgi-bin/uncgi/whatever
(assuming you've installed uncgi and your form has fields
called email and feedback).

It ain't pretty, but if you don't need a fully-parsed XML
solution, it'll work. If you're stuck with Windows, though,
you have my deepest sympathies. Maybe use Cygwin?

--------------------------<snip>------------------------------
#! /bin/sh

# Bourne shell script to add email address and comment
# to an XML file guestbook

# Dependencies: uncgi
# (http://www.midwinter.com/~koreth/uncgi.html)
# The guestbook directory and file index.xml must be
# owned by the web server process (eg apache)

DIR=/var/www/html/guestbook
FILE=index.xml
TEMP=/tmp/index.xml

################################################## ####

cd $DIR

LINES=`cat $FILE | wc -l`
LINES=$[LINES-1]

head -$LINES $FILE >$TEMP

echo \<record\> >>$TEMP
echo \<email\>$WWW_email\</email\> >>$TEMP
echo \<feedback\>$WWW_feedback\</feedback\> >>$TEMP
echo \</record\> >>$TEMP
echo \</data\> >>$TEMP

cp $TEMP $FILE

exit 0
------------------------<snip>-------------------------

///Peter
--
XML FAQ: http://xml.silmaril.ie/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Appending Data to XML File Emmanuel Java 3 10-15-2006 02:35 AM
appending data to xml file Emmanuel XML 2 10-13-2006 04:24 PM
appending data to an xml file Thomas Heller Python 1 01-12-2005 02:25 AM
Appending to XML Andrew Cholakian Perl 0 07-17-2003 08:27 PM
dynamically appending elements to xml file Red Ogden XML 0 07-16-2003 08:29 AM



Advertisments