Re: Appending XML

Discussion in 'XML' started by Jim, Apr 27, 2006.

  1. Jim

    Jim Guest

    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></email>
    <feedback>some feedback</feedback>
    </record>
    </data>

    "Jim" <> wrote in message
    news:juT3g.1640$...
    > 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?
    >
     
    Jim, Apr 27, 2006
    #1
    1. Advertising

  2. > "Jim" <> wrote in message
    > news:juT3g.1640$...
    >
    >>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></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.)
     
    Johannes Koch, Apr 27, 2006
    #2
    1. Advertising

  3. Jim

    Peter Flynn Guest

    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></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/
     
    Peter Flynn, Apr 27, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Cholakian

    Appending to XML

    Andrew Cholakian, Jul 17, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,051
    Andrew Cholakian
    Jul 17, 2003
  2. Red Ogden
    Replies:
    0
    Views:
    1,106
    Red Ogden
    Jul 16, 2003
  3. Thomas Heller

    appending data to an xml file

    Thomas Heller, Jan 11, 2005, in forum: Python
    Replies:
    1
    Views:
    355
    Peter Hansen
    Jan 12, 2005
  4. Emmanuel

    Appending Data to XML File

    Emmanuel, Oct 13, 2006, in forum: Java
    Replies:
    3
    Views:
    331
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Oct 15, 2006
  5. Emmanuel

    appending data to xml file

    Emmanuel, Oct 13, 2006, in forum: XML
    Replies:
    2
    Views:
    456
    Richard Tobin
    Oct 13, 2006
Loading...

Share This Page