Basic XML editor example

Hello,

Please find below the XForms example I demonstrated at XML Prague 2011 
for the MarkLogic DemoJam.

It's a very basic XML editor. Only text contents can be modified and 
mixed content is not supported.

Thank you for your feedbacks!

-Alain
------------------------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:xf="http://www.w3.org/2002/xforms" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ev="http://www.w3.org/2001/xml-events">
<head>
<title>Basic XML Editor</title>
<xf:model>
<xf:instance xmlns="">
<xforms-dummy/>
</xf:instance>
<xf:instance xmlns="" id="data-saved">
<data>
<safe>true</safe>
</data>
</xf:instance>
<xf:bind id="nonempty" nodeset=".[local-name() != 'xforms-dummy']"/>
<xf:bind id="notsafe" nodeset="instance('data-saved')/safe" relevant=". 
!= true()"/>
<xf:submission id="save" method="put" replace="none" action="file://">
<xf:message level="modeless" ev:event="xforms-submit-error">Save 
aborted.</xf:message>
<xf:setvalue ref="instance('data-saved')/safe" value="true()" 
ev:event="xforms-submit-done"/>
</xf:submission>
<xf:submission id="load" method="get" serialization="none" 
replace="instance" action="file://">
<xf:setvalue ref="instance('data-saved')/safe" value="true()" 
ev:event="xforms-submit-done"/>
</xf:submission>
<xf:send submission="load" ev:event="xforms-ready"/>
<xf:send submission="save" ev:event="xforms-model-destruct" 
if="instance('data-saved')/safe = false()"/>
</xf:model>
</head>
<body>
<h1>Basic XML Editor</h1>
<xf:trigger>
<xf:label>Load from local disk</xf:label>
<xf:action ev:event="DOMActivate">
<xf:send submission="save" if="instance('data-saved')/safe = false()"/>
<xf:send submission="load"/>
</xf:action>
</xf:trigger>
<xf:submit bind="notsafe" submission="save">
<xf:label>Save to local disk</xf:label>
</xf:submit>
<br/>
<br/>
<xf:group bind="nonempty">
<xf:repeat nodeset="/descendant::*">
<xf:output 
value="substring('&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;',1,3 
* (count(current()/ancestor::*)+1))"/>
<xf:output value="if(*, '-&#xA0;', '')"/>
<xf:output value="local-name()"/>
<xf:repeat nodeset="@*">
<xf:output 
value="substring('&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;',1,3 
* (count(current()/ancestor::*)+1))"/>
<xf:output value="concat('@',local-name())"/>
<xf:input ref="." incremental="true">
<xf:label>: </xf:label>
<xf:setvalue ref="instance('data-saved')/safe" value="false()" 
ev:event="xforms-value-changed"/>
</xf:input>
</xf:repeat>
<xf:output 
value="if(@*,substring('&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;',1,3 
* (count(current()/ancestor::*)+2)),':')"/>
<xf:input ref=".[not(*)]" incremental="true">
<xf:setvalue ref="instance('data-saved')/safe" value="false()" 
ev:event="xforms-value-changed"/>
</xf:input>
</xf:repeat>
</xf:group>
</body>
</html>

Received on Sunday, 3 April 2011 20:17:17 UTC