data export for subsequent transformation to csv

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

data export for subsequent transformation to csv

ther
Readers,

I am trying to create a form to save data, for eventual import to a
postgresql database. The following file was created:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:xf="http://www.w3.org/2002/xforms">
        <head>
                <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
                <style type="text/css" id="internalstylesheet">
                        code {text-color:black; background:white; font-family:verdana, sans-serif}
                </style>
                <xf:model>
                        <xf:instance>
                                <xf:testform xmlns='generalinformation'>
                                        <xf:generalinformation/>
                                </xf:testform>
                        </xf:instance>
                        <xf:submission
                                resource='file:testgeneral.xml'
                                method="put"
                                id="gi"
                                includenamespaceprefixes=""
                        />
                </xf:model>
                <title>
                test xml to csv for postgresql
                </title>
        </head>
        <body>
                <p>
                        <xf:select1 appearance='minimal'>
                                <xf:label>purpose
                                </xf:label>
                                <xf:item>
                                        <xf:label>
                                                England
                                        </xf:label>
                                        <xf:value>
                                                Building
                                        </xf:value>
                                </xf:item>
                                <xf:item>
                                        <xf:label>
                                                Scotland
                                        </xf:label>
                                        <xf:value>
                                                Building
                                        </xf:value>
                                </xf:item>
                                <xf:item>
                                        <xf:label>
                                                Northern Ireland
                                        </xf:label>
                                        <xf:value>
                                                Building
                                        </xf:value>
                                </xf:item>
                                <xf:item>
                                        <xf:label>
                                                Energy England
                                        </xf:label>
                                        <xf:value>
                                                joule
                                        </xf:value>
                                </xf:item>
                                <xf:item>
                                        <xf:label>
                                                Energy Wales
                                        </xf:label>
                                        <xf:value>
                                                joule
                                        </xf:value>
                                </xf:item>
                                <xf:item>
                                        <xf:label>
                                                Energy Scotland
                                        </xf:label>
                                        <xf:value>
                                                joule
                                        </xf:value>
                                </xf:item>
                                <xf:item>
                                        <xf:label>
                                                Energy Northern Ireland
                                        </xf:label>
                                        <xf:value>
                                                joule
                                        </xf:value>
                                </xf:item>
                        </xf:select1>
                </p>
                <p>
                        <xf:select1 appearance='minimal'>
                                <xf:label>Weather location
                                </xf:label>
                                <xf:item>
                                        <xf:label>
                                                London
                                        </xf:label>
                                        <xf:value>London
                                        </xf:value>
                                </xf:item>
                        </xf:select1>
                </p>
                        <xf:submit submission='gi'>
                                <xf:label>
                                        Send
                                </xf:label>
                        </xf:submit>
        </body>
        </html>

The resultant xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<xf:testform xmlns:xf="http://www.w3.org/2002/xforms"
xmlns="generalinformation">
                                        <xf:generalinformation/>
                                </xf:testform>

If I selected 'England' and 'London' in the form, I was expecting an
xml file containing these values and I expected to need to create an
xslt file for a csv file to be produced. What is my mistake to create
the xml file?

yours,

[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: data export for subsequent transformation to csv

Aaron Reed
Your select1's aren't bound to any data nodes in the instance document.
  So selecting a value in a select1 won't change the instance document.
  Then you'll either have to pre-populate the instance document with the
nodes that you want the select1 item selection to change or use a
xf:insert action to build the instance document.

I hope that this helps get you on the right track,
--Aaron

e-letter wrote:

> Readers,
>
> I am trying to create a form to save data, for eventual import to a
> postgresql database. The following file was created:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
> xmlns:xf="http://www.w3.org/2002/xforms">
> <head>
> <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
> <style type="text/css" id="internalstylesheet">
> code {text-color:black; background:white; font-family:verdana, sans-serif}
> </style>
> <xf:model>
> <xf:instance>
> <xf:testform xmlns='generalinformation'>
> <xf:generalinformation/>
> </xf:testform>
> </xf:instance>
> <xf:submission
> resource='file:testgeneral.xml'
> method="put"
> id="gi"
> includenamespaceprefixes=""
> />
> </xf:model>
> <title>
> test xml to csv for postgresql
> </title>
> </head>
> <body>
> <p>
> <xf:select1 appearance='minimal'>
> <xf:label>purpose
> </xf:label>
> <xf:item>
> <xf:label>
> England
> </xf:label>
> <xf:value>
> Building
> </xf:value>
> </xf:item>
> <xf:item>
> <xf:label>
> Scotland
> </xf:label>
> <xf:value>
> Building
> </xf:value>
> </xf:item>
> <xf:item>
> <xf:label>
> Northern Ireland
> </xf:label>
> <xf:value>
> Building
> </xf:value>
> </xf:item>
> <xf:item>
> <xf:label>
> Energy England
> </xf:label>
> <xf:value>
> joule
> </xf:value>
> </xf:item>
> <xf:item>
> <xf:label>
> Energy Wales
> </xf:label>
> <xf:value>
> joule
> </xf:value>
> </xf:item>
> <xf:item>
> <xf:label>
> Energy Scotland
> </xf:label>
> <xf:value>
> joule
> </xf:value>
> </xf:item>
> <xf:item>
> <xf:label>
> Energy Northern Ireland
> </xf:label>
> <xf:value>
> joule
> </xf:value>
> </xf:item>
> </xf:select1>
> </p>
> <p>
> <xf:select1 appearance='minimal'>
> <xf:label>Weather location
> </xf:label>
> <xf:item>
> <xf:label>
> London
> </xf:label>
> <xf:value>London
> </xf:value>
> </xf:item>
> </xf:select1>
> </p>
> <xf:submit submission='gi'>
> <xf:label>
> Send
> </xf:label>
> </xf:submit>
> </body>
> </html>
>
> The resultant xml file is:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xf:testform xmlns:xf="http://www.w3.org/2002/xforms"
> xmlns="generalinformation">
> <xf:generalinformation/>
> </xf:testform>
>
> If I selected 'England' and 'London' in the form, I was expecting an
> xml file containing these values and I expected to need to create an
> xslt file for a csv file to be produced. What is my mistake to create
> the xml file?
>
> yours,
>
> [hidden email]
>
>
>




Reply | Threaded
Open this post in threaded view
|

Re: data export for subsequent transformation to csv

Klotz, Leigh
In reply to this post by ther
I hope this message reaches you as your email address doesn't seem accurate, but perhaps you'll see it on the list.

There are a couple of issues with your form:

1. The instance should start out with elements for all the elements you want in the result.  In general, XForms form controls only change the text values of elements and attributes, and don't add them.  (There are a few cases where they do get added by controls and actions, but in the case of your form, they don't.)

2. The use of namespaces in the instance isn't quite right.   You might want to read up on an XML book on the topic, or just take a look at what I've done and generalize.

3. Each form control needs a "ref" attribute with the path to the element in the instance where you want the data placed.   I've put some in that work, but you can of course change the instance data around.  If you need to move the elements down a level inside other elements, you'll need to use the XPath syntax "a/b/c" to get to element "c" inside "b" inside "a".  In XForms, you get the toplevel element name for free.

That ought to be make it work.  Here's the output I got once I made those changes:

<generalinformation><purpose>Building</purpose><weatherLlocation>London</weatherLocation></generalinformation>

Here's the updated form, and below that are some enhancements you might consider:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">
  <head>
    <style type="text/css">
      code {text-color:black; background:white; font-family:verdana, sans-serif}
    </style>
    <xf:model>
      <xf:instance>
        <generalinformation xmlns="">
          <purpose />
          <weatherLocation />
        </generalinformation>
      </xf:instance>
      <xf:submission resource='file:testgeneral.xml' method="put" id="gi" />
    </xf:model>
    <title>
      test xml to csv for postgresql
    </title>
  </head>
  <body>
    <p>
      <xf:select1 ref="purpose" appearance='minimal'>
        <xf:label>purpose</xf:label>
        <xf:item>
          <xf:label>England</xf:label>
          <xf:value>Building</xf:value>
        </xf:item>
        <xf:item>
          <xf:label>Scotland</xf:label>
          <xf:value>Building</xf:value>
        </xf:item>
        <xf:item>
          <xf:label>Northern Ireland</xf:label>
          <xf:value>Building</xf:value>
        </xf:item>
        <xf:item>
          <xf:label>Energy England</xf:label>
          <xf:value>joule</xf:value>
        </xf:item>
        <xf:item>
          <xf:label>Energy Wales</xf:label>
          <xf:value>joule</xf:value>
        </xf:item>
        <xf:item>
          <xf:label>Energy Scotland</xf:label>
          <xf:value>joule</xf:value>
        </xf:item>
        <xf:item>
          <xf:label>Energy Northern Ireland</xf:label>
          <xf:value>joule</xf:value>
        </xf:item>
      </xf:select1>
    </p>
    <p>
      <xf:select1 ref="weatherLocation" appearance='minimal'>
        <xf:label>Weather location</xf:label>
        <xf:item>
          <xf:label>London</xf:label>
          <xf:value>London</xf:value>
        </xf:item>
      </xf:select1>
    </p>
    <xf:submit submission='gi'>
      <xf:label>Send</xf:label>
    </xf:submit>
  </body>
</html>

4. Not all XForms processors support method="put" to file: URIs, but yours apparently does.  I suspect this is just a test though and you'll be using put or post to an http: URI eventually.


5. You might also want to keep the form from being submitted until the user chooses some data. 

You can do this in two ways:

6a. You can start off with initial data:

      <xf:instance>
        <generalinformation xmlns="">
          <purpose>Building</purpose>
          <weatherLocation>London</weatherLocation>
        </generalinformation>
      </xf:instance>

6b. Or you can use a "bind" element to say that the values must be non-empty (required):

      <xf:model>
      <xf:instance>
        <generalinformation xmlns="">
          <purpose />
          <weatherLocation />
        </generalinformation>
      </xf:instance>
      <xf:bind nodeset="purpose" required="true()" />
      <xf:bind nodeset="weatherLocation" required="true()" />
      <xf:submission resource='file:testgeneral.xml' method="put" id="gi" />
    </xf:model>

6c. You can do both!

7.  There's another slight issue you might encounter if you decide to use this same style of form to edit existing data.  Note that information gets lost in the "purpose" selection.  A user might pick "Scotland", but the data that's produced is indistinguishable from England or Northern Ireland, so if you were to load the form again and provide the instance data with those values, the form would show England (since it's the first match to the value "Building"). There are ways to do this mid-tier logic inside XForms, but you might consider putting this decision logic into your server side, and letting the form just collect the data (England, Scotland, Energy Wales, etc.) 

Please write back if you have questions.

Leigh.

On 08/12/2010 03:28 AM, e-letter wrote:
Readers,

I am trying to create a form to save data, for eventual import to a
postgresql database. The following file was created:

<...

If I selected 'England' and 'London' in the form, I was expecting an
xml file containing these values and I expected to need to create an
xslt file for a csv file to be produced. What is my mistake to create
the xml file?

yours,

[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: data export for subsequent transformation to csv

ther
On 12/08/2010, Leigh L Klotz Jr <[hidden email]> wrote:
>I hope this message reaches you as your email address doesn't seem accurate, but perhaps you'll see it on the list.
>
I looked at the mail archive but could not see any messages for this month?

>There are a couple of issues with your form:
>
>1. The instance should start out with elements for all the elements you want in the result.  In general, XForms form controls only change the text values of elements and attributes, and don't add them.  (There are a few cases where they do get added by controls and actions, but in the case of your form, they don't.)
>
Referring to the w3 document 'xforms11', an example model element is produced:

<xforms:model>
  <xforms:instance>
    <ecommerce xmlns="">
      <method/>
      <number/>
      <expiry/>
    </ecommerce>
  </xforms:instance>
  <xforms:submission action="http://example.com/submit" method="post"
id="submit" includenamespaceprefixes=""/>
</xforms:model>

and applied to an html document:

...
<select1 ref="method">
  <label>Select Payment Method:</label>
  <item>
    <label>Cash</label>
    <value>cash</value>
  </item>
  <item>
    <label>Credit</label>
    <value>cc</value>
  </item>
</select1>
...

I concluded from this example that if I create an element 'testform'
with a namespace 'generalinformation', the element 'select1' with
attribute 'ref='generalinformation'' could be applied. This did not
work so I removed the attribute 'ref'.

>2. The use of namespaces in the instance isn't quite right.   You might want to read up on an XML book on the topic, or just take a look at what I've done and generalize.
>
>3. Each form control needs a "ref" attribute with the path to the element in the instance where you want the data placed.   I've put some in that work, but you can of course change the instance data around.  If you need to move the elements down a level inside other elements, you'll need to use the XPath syntax "a/b/c" to get to element "c" inside "b" inside "a".  In XForms, you get the toplevel element name for free.
>
>That ought to be make it work.  Here's the output I got once I made those changes:
>
><generalinformation><purpose>Building</purpose><weatherLlocation>London</weatherLocation></generalinformation>
>
>Here's the updated form, and below that are some enhancements you might consider:
>
><?xml version="1.0" encoding="UTF-8"?>
><html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">
>  <head>
>    <style type="text/css">
>      code {text-color:black; background:white; font-family:verdana, sans-serif}
>    </style>
>    <xf:model>
>      <xf:instance>
>        <generalinformation xmlns="">
>          <purpose />
>          <weatherLocation />
>        </generalinformation>
>      </xf:instance>
>      <xf:submission resource='file:testgeneral.xml' method="put" id="gi" />
>    </xf:model>
>    <title>
>      test xml to csv for postgresql
>    </title>
>  </head>
>  <body>
>    <p>
>      <xf:select1 ref="purpose" appearance='minimal'>

The addition of the attribute 'ref' causes the list menu to disappear
(tested in firefox version 2009, 304, 36rc2 and now using 368, all
with suitable versions of the xforms plugin). All that appears is the
button icon labelled 'send'. When I remove the attribute 'ref', the
list menu reappears.

René.

Reply | Threaded
Open this post in threaded view
|

Re: data export for subsequent transformation to csv

Aaron Reed
Hi René,

If you put a ref attribute on a control and it doesn't show up in the
form, then the odds are the xpath expression you used was incorrect.
Binding a form control to a non-existent node implies that the control
is not relevant and the default behavior in the Firefox xforms processor
is to hide non-relevant controls.  Please try the example that Leigh
posted.  It works fine for me in Firefox 3.6.8 using the mozilla xforms
extension v0.8.7.

I also think you might be well served to perhaps read some xforms
introductory information like:
http://www.w3.org/MarkUp/Forms/2003/xforms-for-html-authors.html or
perhaps http://en.wikibooks.org/wiki/XForms.  When you mentioned setting
the namespace of the node to 'generalinformation' and then trying to use
ref='generalinformation', it makes me think that perhaps you've missed
some key concepts about xforms.  For example, the values of @bind and
@ref (and other xforms attributes) should be xpath expressions, not
namespace strings.  Hopefully reading the above information will get you
on the right track.  If you still have problems, please let us know.

--Aaron

e-letter wrote:

> On 12/08/2010, Leigh L Klotz Jr<[hidden email]>  wrote:
>> I hope this message reaches you as your email address doesn't seem accurate, but perhaps you'll see it on the list.
>>
> I looked at the mail archive but could not see any messages for this month?
>
>> There are a couple of issues with your form:
>>
>> 1. The instance should start out with elements for all the elements you want in the result.  In general, XForms form controls only change the text values of elements and attributes, and don't add them.  (There are a few cases where they do get added by controls and actions, but in the case of your form, they don't.)
>>
> Referring to the w3 document 'xforms11', an example model element is produced:
>
> <xforms:model>
>    <xforms:instance>
>      <ecommerce xmlns="">
>        <method/>
>        <number/>
>        <expiry/>
>      </ecommerce>
>    </xforms:instance>
>    <xforms:submission action="http://example.com/submit" method="post"
> id="submit" includenamespaceprefixes=""/>
> </xforms:model>
>
> and applied to an html document:
>
> ...
> <select1 ref="method">
>    <label>Select Payment Method:</label>
>    <item>
>      <label>Cash</label>
>      <value>cash</value>
>    </item>
>    <item>
>      <label>Credit</label>
>      <value>cc</value>
>    </item>
> </select1>
> ...
>
> I concluded from this example that if I create an element 'testform'
> with a namespace 'generalinformation', the element 'select1' with
> attribute 'ref='generalinformation'' could be applied. This did not
> work so I removed the attribute 'ref'.
>
>> 2. The use of namespaces in the instance isn't quite right.   You might want to read up on an XML book on the topic, or just take a look at what I've done and generalize.
>>
>> 3. Each form control needs a "ref" attribute with the path to the element in the instance where you want the data placed.   I've put some in that work, but you can of course change the instance data around.  If you need to move the elements down a level inside other elements, you'll need to use the XPath syntax "a/b/c" to get to element "c" inside "b" inside "a".  In XForms, you get the toplevel element name for free.
>>
>> That ought to be make it work.  Here's the output I got once I made those changes:
>>
>> <generalinformation><purpose>Building</purpose><weatherLlocation>London</weatherLocation></generalinformation>
>>
>> Here's the updated form, and below that are some enhancements you might consider:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">
>>   <head>
>>     <style type="text/css">
>>       code {text-color:black; background:white; font-family:verdana, sans-serif}
>>     </style>
>>     <xf:model>
>>       <xf:instance>
>>         <generalinformation xmlns="">
>>           <purpose />
>>           <weatherLocation />
>>         </generalinformation>
>>       </xf:instance>
>>       <xf:submission resource='file:testgeneral.xml' method="put" id="gi" />
>>     </xf:model>
>>     <title>
>>       test xml to csv for postgresql
>>     </title>
>>   </head>
>>   <body>
>>     <p>
>>       <xf:select1 ref="purpose" appearance='minimal'>
>
> The addition of the attribute 'ref' causes the list menu to disappear
> (tested in firefox version 2009, 304, 36rc2 and now using 368, all
> with suitable versions of the xforms plugin). All that appears is the
> button icon labelled 'send'. When I remove the attribute 'ref', the
> list menu reappears.
>
> René.
>
>




Reply | Threaded
Open this post in threaded view
|

Re: data export for subsequent transformation to csv

ther
On 13/08/2010, Aaron Reed <[hidden email]> wrote:

> Hi René,
>
> If you put a ref attribute on a control and it doesn't show up in the
> form, then the odds are the xpath expression you used was incorrect.
> Binding a form control to a non-existent node implies that the control
> is not relevant and the default behavior in the Firefox xforms processor
> is to hide non-relevant controls.  Please try the example that Leigh
> posted.  It works fine for me in Firefox 3.6.8 using the mozilla xforms
> extension v0.8.7.
>
The example created by Leigh works, when I used another computer with
firefox 20018; thank you.

I have been reading mainly the xforms 11 specification and the
documents xforms for authors parts 1 & 2.

A brief explanation of my project: I am trying to create an open
source software version of a modelling and reporting system that uses
m$ access. So far I have converted access tables to postgresql tables.
The intention is to create an xform that the user enters data,
eventually saving as a single xml file. Then the user should sign in
to a web site and submit the xml file to the web server. Data is
processed and the result is that the user is able to produce a report
(e.g. a colourful histogram of energy consumption in an office).

My understanding so far is that transferring xml formatted data to a
postgresql database server is not directly possible and so my next
plan is to use xslt to convert the xml file into csv tables for
subsequent entry to the database.

Thank you for your initial help; onto xslt!