W3C home > Mailing lists > Public > www-forms@w3.org > December 2006

RE: Open, edit, save XML file--help or example

From: Klotz, Leigh <Leigh.Klotz@xerox.com>
Date: Wed, 20 Dec 2006 10:31:01 -0800
Message-ID: <E254B0A7E0268949ABFE5EA97B7D0CF4029633F7@usa7061ms01.na.xerox.net>
To: "Colin Sagan" <colin@cmbf.org>, <www-forms@w3.org>

Colin,
I don't think FormFaces is going to be able to save to a local file with
a file:// URI, but you can ask on the FormFaces list at SourceForge.
You can do it through a web server if the web server implements PUT; you
probably have to specially enable PUT on the directory you want the
files to be placed in, using your web servers configuration.  It's not
too onerous for apache -- check on the syntax of ".htaccess" files.

You can also change your put to a post and write a small script to save
the data to a file.
Since the data posted is already the XML file, you should just be able
to write it directly to a file.
You still should probably use .htaccess or some other mechanism to
preform authentication first, though!

As for re-ordering, you will need to do that by posting to a script on
the server side and using replace='instance' to get the data back;
XForms 1.0 offers very little for structural modification of the XML
file.  You will find the insert and delete actions, though, which can
operate on repeating structure, so you should be able to add a new dish
at any point in the list.  There's an example of this in the XForms 1.0
Recommendation, tested in X-Smiles, and another one (apparently updated
to work with the pecularities of Mozilla XForms) in
http://en.wikibooks.org/wiki/XForms/Hierarchical_Bookmarks

Please write back if you have other specific questions.

Leigh.

-----Original Message-----
From: www-forms-request@w3.org [mailto:www-forms-request@w3.org] On
Behalf Of Colin Sagan
Sent: Saturday, December 16, 2006 10:51 PM
To: www-forms@w3.org
Subject: Open, edit, save XML file--help or example


Hello,
I am working on a system for a restaurant to update it's menu easily  
and I thought I'd take the opportunity to sink my teeth into xforms.  
I've got it displaying but I can't get it to save, and I haven't had  
much luck finding good examples of this process.

Currently I am trying to use the formfaces javascript but have by no  
means exhausted the options. Just seemed like the easiest given that  
I don't have a lot of experience with apache and the plugins are too  
limited in terms of mobility.

So this is what I've patched together from different examples, also,  
next I want to get reordering and insert/delete working so if there  
is anything I'm doing currently that will prevent that I would  
appreciate suggestions to make that easier.
Thanks,
Colin


<?xml version="1.0" encoding="UTF-8"?>
<html
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xf="http://www.w3.org/2002/xforms"
	xmlns:ev="http://www.w3.org/2001/xml-events">
<head>

<xf:model>
   <xf:instance src="breakfast-edit_test.xml" xmlns="" />
   <xf:submission id="read-from-file" method="get" action="breakfast- 
edit_test.xml" replace="instance" />
   <xf:submission id="save-to-file" method="put" action="breakfast- 
edit_test.xml" />

</xf:model>
</head>

<body>
<fieldset>
	<legend>Menu</legend>
	<xf:repeat id="courses" nodeset="/menu/course">
	<xf:input ref="courseTitle">
		<xf:label>Course Title</xf:label>
	</xf:input>
	<xf:textarea ref="courseDescription">
		<xf:label>Course Description</xf:label>
	</xf:textarea>	
	
	<xf:repeat id="dishes" nodeset="dish">
		<xf:textarea ref="description">
			<xf:label>Description</xf:label>
		</xf:textarea>
		<xf:input ref="price">
			<xf:label>Price</xf:label>
		</xf:input>	
	</xf:repeat>
	</xf:repeat>
</fieldset>

<xf:submit submission="read-from-file">
	<xf:label>Reload</xf:label>
</xf:submit>

<xf:trigger>
	<xf:label>Save</xf:label>
	<xf:action ev:event="DOMActivate">
		<xf:send submission="read-from-file" />
	</xf:action>
</xf:trigger>

</body>
</html>

________________________________________
And the XML file (I cut it down to one dish per course so it doesn't  
take up so much room!


<?xml version="1.0" encoding="UTF-8"?>
<menu id="breakfast">
	<date />
	<course>
		<courseTitle>Coffee Bar</courseTitle>
		<courseDescription>Bluebottle Coffee -- Dogpatch Blend
(regular/decaf)
		</courseDescription>
		<dish>
			<description>Espresso</description>
			<price>2.50</price>
		</dish>
		<dish>
			<description>Espresso with organic milk,
macchiato, cappuccino, latte
			</description>
			<price>3.25</price>
		</dish>
		<dish>
			<description>Drip Coffee</description>
			<price>2.00</price>
		</dish>
		<dish>
			<description>Mighty Leaf Green Tea &amp; Classic
Darjeeling</ 
description>
			<price>2.75</price>
		</dish>
		<dish>
			<description>Fresh leaves, lemon verbena herbal
tea</description>
			<price>2.75</price>
		</dish>
	</course>
	
	<course>
		<courseTitle>Grab &amp; Go</courseTitle>
		<courseDescription />
		<dish>
			<description>Hard boiled egg with
herbed/flavored salts</description>
			<price>1.00</price>
		</dish>
		<dish>
			<description>Seasonal fruit</description>
			<price>1.75</price>
		</dish>
	</course>
	
	<course>
		<courseTitle>Bakery</courseTitle>
		<courseDescrption />
		<dish>
			<description>Ginger scones</description>
			<price>2.25</price>
		</dish>
		<dish>
			<description>Croissants</description>
			<price>2.25</price>
		</dish>
		<dish>
			<description>Pain au chocolat</description>
			<price>2.75</price>
		</dish>
		<dish>
			<description>Canelets</description>
			<price>2.25</price>
		</dish>
		<dish>
			<description>Biscotti</description>
			<price>1.00</price>
		</dish>
	</course>
	
	<course>
		<courseTitle>Breakfast Pizza</courseTitle>
		<courseDescription>Served 7:30 to
10:00am</courseDescription>
		<dish>
			<description>Egg and truffle -- Pizza crust,
sunny side up egg,  
truffle olive oil</description>
			<price>7.75</price>
		</dish>
		<dish>
			<description>Bacon &amp; eggs scramble -- Hobbs
bacon and eggs,  
scrambled</description>
			<price>7.75</price>
		</dish>
	</course>
</menu>
Received on Wednesday, 20 December 2006 18:31:44 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:08 GMT