简体   繁体   English

如何使用 eXist-db 和 xsltForms 通过浏览器编辑 xml 文件

[英]How to edit a xml file via browser with eXist-db and xsltForms

I am relatively new to eXist-db.我对 eXist-db 比较陌生。 I have already built an application which displays XML documents in the browser, and implemented a basic search.我已经构建了一个在浏览器中显示 XML 文档的应用程序,并实现了一个基本的搜索。

I have an .xml file which functions as a database;我有一个用作数据库的 .xml 文件; it contains records such as:它包含以下记录:

 <person xml:id="pe0001"> <persName> <surname>Name</surname> <forename>Surname</forename> </persName> </person>

I would like to be able to edit this file via the browser;我希望能够通过浏览器编辑此文件; for instance, edit a person's name, or add a new record.例如,编辑一个人的姓名,或添加一个新记录。

I have gone through eXist-db documentation, looked at the examples, read wikibooks - I haven't found what I need yet.我浏览了 eXist-db 文档,查看了示例,阅读了 wikibooks - 我还没有找到我需要的东西。 I just need a text area in which someone can input/edit some text which will be pushed (using PUT, I guess) into the .xml file.我只需要一个文本区域,有人可以在其中输入/编辑一些将被推送(我猜是使用 PUT)到 .xml 文件中的文本。

Is XSLTForms the best option for me? XSLTForms 是我的最佳选择吗? Could anyone be so kind to give me some sort of direction/suggestion/example?谁能给我一些方向/建议/例子? Thanks!谢谢!

I think for relatively simple records like you've shown as example, good ole HTML forms would be the simplest solution, triggering an XQuery script on the eXist-db side that actually updates the data.我认为对于像您作为示例显示的相对简单的记录,好的 ole HTML 表单将是最简单的解决方案,在实际更新数据的 eXist-db 端触发 XQuery 脚本。 XForms, say, offer little gain and there's surely a steep learning curve involved.例如,XForms 提供的收益很小,而且肯定涉及一个陡峭的学习曲线。

Thanks for the downvote :) .感谢您的反对:)。 Anyway, I have created a .xq file which grabs the id of the node I want to edit with无论如何,我已经创建了一个 .xq 文件,它获取了我想要编辑的节点的 id

let $id := request:get-parameter("id", "")

and then returns this html code:然后返回这个 html 代码:

head

 <xf:model> <xf:instance id="data-instance" src="my.xml" xmlns="http://www.tei-c.org/ns/1.0" /> <xf:submission id="read-from-file" method="get" action="my.xml" replace="instance" instance="data-instance" /> <xf:submission id="save-to-file" method="put" action="my.xml" replace="instance" instance="data-instance" /> </xf:model>

body身体

 <xf:input xmlns="" ref="//tei:person[@xml:id='{$id}']/tei:persName/tei:surname"> <xf:label>Surname</xf:label> </xf:input> <xf:input xmlns="" ref="//tei:person[@xml:id='{$id}']/tei:persName/tei:forename"> <xf:label>Name</xf:label> </xf:input>

Once edited the text, the user submits it via the following button:编辑文本后,用户通过以下按钮提交:

 <xf:submit submission="save-to-file"> <xf:label>Save</xf:label> </xf:submit>

depending on use case, you might want to take a look at how the default documentation app let's users open (and run) an example in eXide (using loadsource.js).根据用例,您可能想看看默认文档应用程序如何让用户在 eXide 中打开(和运行)示例(使用 loadsource.js)。

For simple xml editing eXide is plenty capable.对于简单的 xml 编辑,eXide 功能强大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM