Custom XML in ODF (XForms) Part 1

by jlundstocholm 28. April 2008 20:19

For some time now I have had an urge to see how to do "Custom XML" or "Custom Schemas" in ODF. Saturday evening after the BRM in Geneva I was sitting in the bar at the Kempinsky Hotel at the lake - naturally talking tech-stuff. We talked about the usual ODF/OOXML-stuff and touched upon the subject of Custom XML. I was told that ODF would not have Custom XML capabilities since the ODF TC thought it was good enough to do it with XForms.

Cool, I thought ... I need to test this.

For this first test I have used the UI of OpenOffice.org 2.4 to create an XForm-enabled document with some basic data in it. I will dig deeper into the technicalities later but OOo UI will do for now. I have been searchning high and low for tutorials on XForms and their usage in ODF, and finally I found this article by J. David Eisenberg on xml.org The article is from 2006. I have made a more simple document for this test - avaliable here: xforms.odt (8,98 kb).

I have created a small form to enable the user to type in some basic data, e.g. "name", "phone" and "email".


The idea is to be able to map the typed-in data to a XML-structure. In my case the structure is this:

<xforms:instance id="clubData">
    <club>
        <name />
        <contact>
            <name />
            <phone />
            <email />
            <city />
        </contact>
    </club>
</xforms:instance>

I have set up the document to do more or less what the original article did so let's look at what is really persisted in the ODF-package. An XForm is basically a connection between "input fields" like "text boxes", "radio buttons" and "drop-down menus" and some XML in the document. Look at the content of a part of the content.xml-file below (some details have been removed to enhance readability):




So 1) puts a control (input field) next to the text "Club name" with control-id "control1". This control is further defined in 2) where the XForms "bind"-attribute 3) tells the application to bind the  contents of the control to the XML specified with the XPath expression in 4).

It's really cool and nicely set up.

But what about persistance of the data entered in the form fields? Well, you add a button and attach an action to it. I called my button "Persist". What this action does is defined with the XForms "Submission" element.



In short the above describes that the content of the form fields should be persisted in a file on my local hard drive. Other methods could be to post it to a webserver or URI somewhere. This is very similar to how InfoPath works.

But at this moment I have two outstanding issues - and here I could use the help of you guys:

  1. I would really like to persist the data in the ODF-package - but I cannot get my head around making OOo doing it. Is it at all possible?
  2. When I click the button nothing happens - the data is not saved to disk. What am I missing here?


This is my first attempt to work with XForms in ODF, and to me it really seems kind of nifty.

So the guy tossing down beers at the bar in the hotel was kindda right - it is possible to do some kind of CustomXML-embedding in ODF using XForms. I also think, however, that it doesn't make a whole lotta sense to compare XForms with the CustomXML-implementation in OOXML - especially if it is not possible to use XForms actions to save the data directly in the package. In this case it seems to me that XForms should be compared to InfoPath instead.

 

So guys, what do you think? What are your experiences with XForms in ODF?

Smile

Comments

4/29/2008 5:02:45 AM #

pingback

Pingback from blogs.msdn.com

Doug Mahugh : Open XML links for 04-28-2008

blogs.msdn.com |

4/30/2008 6:11:41 PM #

hAl

Aren't you lacking a submit ?

<xforms:submit submission="persistData">
     <xforms:label>Persist</xforms:label>
</xforms:submit>

hAl |

4/30/2008 6:18:45 PM #

jlundstocholm

Hi hAl,

Well, I am not sure - note that I have not created the XForms-enabled ODT document by hand but through the UI of OOo 2.4 .

However, I found this in content.xml:

<form:button form:name="PushButton" form:control-implementation="ooo:com.sun.star.form.component.CommandButton" form:id="control6" form:label="Persist" form:button-type="submit" office:target-frame="" xlink:href="" form:image-data="" form:xforms-submission="persistData" form:delay-for-repeat="PT0.50S" form:image-position="center">
  <form:properties>
    <form:property form:property-name="DefaultControl" office:value-type="string" office:string-value="com.sun.star.form.control.CommandButton" />
  </form:properties>
</form:button>

Shouldn't that do the trick?

jlundstocholm Denmark |

5/21/2008 11:01:40 PM #

Bart H

The trick is to use 3 slashes after "file:" and a slash after the drive instead of a backslash (the action requires an URI, and the hierarchy levels in a URI are separated by a  "forward" slash).

So in this example you should use something like  file:///c:/test.xml
Worked for me in OOo2.4 on WinXP Pro

Moreover, using the "save as" option in OOo, you can just save the form+data to an ODT: the data will be inserted into an <xforms:instance> element


By the way, there's a nice tutorial on the ODF community website: opendocument.xml.org/files/xforms_ooo_06_10_25.pdf

Bart H Belgium |

5/22/2008 6:05:12 PM #

jlundstocholm

Hi Bart,

Thank you for your input. You are correct with the file:///-tip - OOo now saves the XML-fragment to disk just fine. Also, as you point out, choosing "Save as..." persists the typed in data into the ODT-file.

Smile

jlundstocholm Denmark |

8/28/2008 3:34:30 AM #

Carl

  I have been toying with the idea of using XFORMS as a platform independent  way of :

  Inputting data
  Editing data
  Reporting Data

from traditional C and FORTRAN codes.  So for example to input data into my application I would:

  1) From C write a file containing XML instance data to disk
  2) Auto-load an OpenOffice Xform with the instance data
  3) Save the new instance data
  4) Re-read the new XML file into the C program from disk.

Frankly the "web" would have nothing to do with this process, as it could exist on a standalone machine with out any server apps.

  My advantages for this are:
  
  1) Giving what used to be "console" applications a new look and feel on many platforms,

  2) Data entry validation

  3) Data filtering in that the instance data may contain 1000 items but the user of the form could only change 10.

  4) Rapid development of the forms WITHOUT programming, simple GUI drag and drop from a defined XML instance data set.

  Thoughts?

Carl United States |

1/5/2009 4:43:02 PM #

jlundstocholm

Hi Carl,

(I apologize for the long delay in responding to you)

Have you gotten your idea to work? It seems to me like a nice idea, but I am a bit uncertain about a couple of things:

1. Would you generate an entire ODF-document with an XForm in it and then load it into e.g. OOo?

2. It is possible to save the entered content of an XForm into the ODF document itself using OOo - is that also your thought or are you rather saving the entered content somewhere else on disk?

3. How do you handle the correlation/coorporation between OOo and your C/FORTRAN-code? Will e.g. OOo execute the program after data has been sent via something like an macro?

Thanks,

Smile

jlundstocholm Denmark |

5/4/2010 8:30:25 PM #

Electronic Schematic

  not easily explained in a tutorial that explain in detail, and easily understood by visitors. you are a true helper

Electronic Schematic United States |

7/8/2011 2:35:11 AM #

pingback

Pingback from blogs.msdn.com

MSDN Blogs

blogs.msdn.com |

Comments are closed