Email conversation
From | Lucy Evans |
To | Me |
Subject | thanks for HowToCreate script reference |
Date | 20 February 2009 07:47 |
Hello,
I'm completely new to all this XML, Java etc, regarding one of the scripts
you wrote about importing xml; I'm currently working on how to export an
html form data to an xml database to be viewed in an iframe. If you've got
and advice, that would be a huge help. Unfortunately I can't supply a URL as
it's a restricted site and you won't be able to access it. Everything is
already created, the form, the xml database and the ifame is set up on an
html page the only thing we need to do now is link the form to the xml
database. The form would be sent to the users so they could add information
and upload the content themselves. Is this achievable??
I would be grateful for any advice you could give.
Regards
Lucy
From | Me |
To | Lucy Evans |
Subject | Re: thanks for HowToCreate script reference |
Date | 21 February 2009 09:10 |
Lucy,
To summarise, it sounds like you want a form to submit data to the server,
which then puts it inside an XML "database". You also want some way to
extract the contents of that XML, and display it as page content.
This is all something that should be done by the server, not by importing
XML on the client. In other words, you can stop thinking about using my
script - it's not appropriate here, since it cannot edit the XML file
contents. Exactly what server-side language you should use for this will
depend on what languages your hosting server supports. The most popular are
PHP and Perl for Apache servers, and various languages under the ASP.NET
framework on IIS servers. You should ask your host what languages are
available.
Most of these languages will offer some way to easily read and manipulate
XML documents. I will give a sample here in PHP, since that's what I know
best, but you should follow the manuals for the language that you will be
using. This is a simple piece of code that reads XML data from an XML file,
and rewrites it to that file, having added this XML at the end of the root
element's contents:
<item>text from GET form submission input foo</item>
..snipped code that checks that the form submission data is legitimate..
$myDocument = domxml_open_file('datafile.xml');
$root = $myDocument->documentElement;
$newitem = $root->appendChild($myDocument->createElement('item'));
$newitem->appendChild($myDocument->createTextNode($_GET['foo']));
$myDocument->dump_file('datafile.xml');
A similar approach allows you to read and display the contents as part of a
web page:
$myDocument = domxml_open_file('datafile.xml');
$allitems = $myDocument->getElementsByTagName('item');
for( $i = 0; $i < count($allitems); $i++ ) {
print '<p>'.$allitems->item($i)->firstChild->nodeValue.'</p>';
}
Of course, this sample is very naive - it does not do any safety checks to
see if the XML file was successfully opened, etc. but it should be enough to
give you the idea. The DOM support in PHP is based on exactly the same
functionality as the DOM support in browsers, so all the same common methods
and properties are there. Only the syntax is different because it is PHP,
not JavaScript. If you prefer to output the content using XSLT to transform
it into HTML, this is also possible in PHP:
http://www.howtocreate.co.uk/tutorials/jsexamples/importingXML.html#xslt
For more details of manipulating XML in PHP, please read the very extensive
documentation here - it's a lot more useful than I could be:
http://www.php.net/manual/en/refs.xml.php
http://www.php.net/manual/en/class.domdocument.php
Perl has similar functionality in the XML::Parser and XML::DOM modules:
http://search.cpan.org/~msergeant/XML-Parser/
http://search.cpan.org/~tjmather/XML-DOM/
For other languages, see their manuals for what XML manipulation
functionality they provide.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/