Manually loading XML data into XForms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    Manually loading XML data into XForms

    Hello everybody!
    I'm pretty new to XForms and doing a project with XForms and eXist, so I have an XML file as a database. The problem I'm having is the following:

    My XForms document looks something like this:
    [code=xml]
    ...
    <xf:model version="1.0">
    <xf:instance id="data-instance" src="data.xml" xmlns="">
    <Data>
    <FirstName/>
    <LastName/>
    </Data>
    </xf:instance>
    <xf:submissio n id="read-from-file" method="get" action="http://localhost:8080/exist/rest/db/eXist_test/data.xml" replace="instan ce" instance="data-instance"/>
    <xf:submissio n id="save-to-file" method="put" action="http://localhost:8080/exist/rest/db/eXist_test/data.xml" replace="instan ce" instance="data-instance"/>
    </xf:model>
    ...
    <xf:input ref="/Data/FirstName"><xf: label>First Name: </xf:label></xf:input><br/>
    <xf:input ref="/Data/LastName"><xf:l abel>Last Name: </xf:label></xf:input><br/>
    <xf:submit submission="rea d-from-file"><xf:label >Load</xf:label></xf:submit>
    <xf:submit submission="sav e-to-file"><xf:label >Save</xf:label></xf:submit>
    ...
    [/code] and my XML document looks like this:
    Code:
    <Data>
     <FirstName>Peter</FirstName>
     <LastName>Parker</LastName>
    </Data>
    Now, when the document loads, it loads the values from the XML file into the Document, ditto when I click on "Load" and when I click on "Save" it submits the changes to my XML file. So far so good - but now I want to be able to add new tags to the XML file via the webinterface (e.g. <MiddleName>). When I have further paths in my XForms document, they just won't display, unless they belong to a different instance (which isn't a choice I guess, because it will only submit the data of one instance when I save).

    My idea was therefore to cut out the src="data.xml" part in the instance description and just load the entries manually. Also, the read-from-file submission would have to be changed. However, I can't seem to be able to find anything like that online. Any ideas or suggestions, how do do this differently?

    Greetings,
    Nepomuk
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Does nobody have an idea? Any bit of help would be great.

    Greetings,
    Nepomuk

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      sorry, but I only glanced over XForms. you may be able to change the XML by JavaScript, though I didn’t try that either.

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        I just had another thought, maybe this could work, though I have no idea how to implement it:

        Let's assume, when I want to add a new tag, I click on an "Add" button. What happens then, is that a different instance is selected for saving and this instance gets a copy of the data from the original instance plus the new stuff that's supposed to be added. So, the new question would be: How do I copy data from one instance to another?

        Greetings,
        Nepomuk

        Comment

        Working...