是否有程序或脚本可以通过基于 DTD 模式的表单接收用户输入来从 DTD 模式(免费)生成 XML 模型?
我想知道是否存在一个程序可以读取DTD规范,使用规范创建表单或控制台提示,使用表单/提示获取用户输入的数据,然后从输入的数据写入XML文档。
有这样的程序吗?
例如,想象一下:
[开始想象]
我们有以下 DTD 文件来定义 XML 文档的结构:
<!DOCTYPE cd_collection [
<!ELEMENT cd_collection (album+) >
<!ELEMENT album (disc+) >
<!ATTLIST album title CDATA #REQUIRED >
<!ATTLIST album artist CDATA #REQUIRED >
<!ATTLIST album label CDATA #REQUIRED >
<!ELEMENT disc (track*) >
<!ELEMENT track EMPTY >
<!ATTLIST track title CDATA #REQUIRED >
<!ATTLIST track length CDATA #IMPLIED >
<!ATTLIST track featuring CDATA #IMPLIED >
]>
一个程序(例如 PHP 或 Javascript 网站,或者C++ 应用程序),读取 DTD 文件以确定将保存在 XML 文件中的记录的格式。
读取上面的 DTD 文件后,程序将要求用户输入,以便开始创建 XML 树:
Lets create cd_collection...
What is the title attribute of album 1? Barenaked Ladies Are Men [enter]
What is the artist attribute of album 1? Barenaked Ladies [enter]
What is the label attribute of album 1? Raisin Records [enter]
Does album 1 disc 1 contain track(s) (y/n)? yes [enter]
What is the title attribute of album 1 disc 1 track 1? [enter]
Error: this attribute is required.
What is the title attribute of album 1 disc 1 track 1? Serendipity [enter]
What is the length attribute of album 1 disc 1 track 1 (optional)? 4:11 [enter]
What is the featuring attribute of album 1 disc 1 track 1 (optional)? [enter]
What is the title attribute of album 1 disc 1 track 2? Something You'll Never Find [enter]
What is the length attribute of album 1 disc 1 track 2 (optional)? 4:57 [enter]
What is the featuring attribute of album 1 disc 1 track 2 (optional)? [enter]
...
Does album 1 contain another disc (y/n)? [enter]
Error: Yes or No answer expected.
Does album 1 contain another disc (y/n)? n [enter]
Does cd_collection contain another album (y/n)? yes [enter]
What is the title attribute of album 2? Live From Mars [enter]
What is the artist attribute of album 2? Ben Harper [enter]
What is the label attribute of album 2? Virgin Records [enter]
Does album 1 disc 1 contain track(s) (y/n)? y [enter]
What is the title attribute of album 2 disc 1 track 1? Glory & Consequence [enter]
What is the length attribute of album 2 disc 1 track 1 (optional)? [enter]
What is the featuring attribute of album 2 disc 1 track 1 (optional)? [enter]
...
Does album 2 contain another disc (y/n)? y [enter]
...
What is the title attribute of album 2 disc 2 track 6? The Drugs Don't Work [enter]
What is the length attribute of album 2 disc 2 track 1 (optional)? [enter]
What is the featuring attribute of album 2 disc 2 track 1 (optional)? Richard Ashcroft [enter]
...
Does album 2 contain another disc (y/n)? no [enter]
Does cd_collection contain another album (y/n)? n [enter]
Ok! cd_collection saved in ./cd_collection.xml (or outputted to the screen, etc).
因此,您会看到,基于 DTD,程序要求创建 XML 文档所需的所有数据。该程序遵循一种模式:
- 它从树的顶部开始(用户应该在他的树中拥有该树) 想象力,在本例中是 CD 集)并沿着树向下传播 以预购方式。
- 标有“+”的元素至少需要一次,带有“+”的元素 “*”需要零次或多次,带有“?”的元素是 需要零次或一次,没有这样标签的元素是 只需要一次。为了描述的目的,我将 将这些标签称为“数量标签”
- 当程序第一次到达级别 X 的元素时 在到达树的第一个分支末端的途中,它会执行以下操作之一 四件事取决于上述标签:如果元素的 label 是一个“+”或者什么都没有,那么就假设该元素是 必需并继续获取所述元素的属性数据 如果没有属性值,则移动到下一个元素 提示.如果元素的标签是“*”或“?”,则程序 询问用户是否存在这样的元素。如果是,那么该程序 创建元素并在必要时提示输入属性值, 在继续之前。如果不是,则程序跳转到下一个类型 X 层的元素(如果有),否则移回到树上继续 预购。如果 X 层的元素是最终元素,其中包含 #CDATA 或 #PCDATA(等等),然后程序提示输入此类数据,或者 如有必要,将元素保留为空。本质上,元素和 绝对数据点是按预定顺序创建的。
- 当程序跳回树到分支的根时, 程序再次分析数量标签。如果根元素 在级别 X-1 具有“+”或“*”标签,程序会询问是否有更多 这些元素是存在的(将被输入、记录、创建等)。这 是程序发现要遍历的分支的机制 预购中。 X-1 级元素是 X 级元素的根 包含一个“?”标签或什么都不检查,因为它们可以 最多仅存在一个,因此它们的存在(或 不存在)在程序向下遍历时已经确定 树(远离根),如上一步所述。
程序像这样继续(我可能在必要时错过了更多的 DTD 规则),直到它最终返回到根元素(在本例中为 cd_collection),此时程序有足够的信息来编写一个包含所有内容的 XML 文件。获得的数据。
[/结束想象]
在那个想象的场景中,示例是一个命令行程序。然而,它也可以是图形网络界面。例如,不是像这样逐条提示数据:
What is the title attribute of album 2? Live From Mars [enter]
What is the artist attribute of album 2? Ben Harper [enter]
What is the label attribute of album 2? Virgin Records [enter]
它可以以这样的 HTML 形式获取:
album 2:
title: ____Live From Mars____
artist: ____Ben Harper _______
label: ____Virgin Records ___
[submit button]
是否存在这样的程序(或类似程序),最好是免费的?如果有的话,它叫什么名字,在哪里可以找到它?
I'd like to know if there exists a program that can read DTD specifications, use the specifications to create forms or console prompts, use the forms/prompts to obtain user input of data, then write XML documents from the inputted data.
Does there exist such a program?
For example, imagine this:
[begin imagination]
We have the following DTD file to define the structure of an XML document:
<!DOCTYPE cd_collection [
<!ELEMENT cd_collection (album+) >
<!ELEMENT album (disc+) >
<!ATTLIST album title CDATA #REQUIRED >
<!ATTLIST album artist CDATA #REQUIRED >
<!ATTLIST album label CDATA #REQUIRED >
<!ELEMENT disc (track*) >
<!ELEMENT track EMPTY >
<!ATTLIST track title CDATA #REQUIRED >
<!ATTLIST track length CDATA #IMPLIED >
<!ATTLIST track featuring CDATA #IMPLIED >
]>
A program (say a PHP or Javascript website, or a C++ application), reads the DTD file to determine the format of the records that will be kept in an XML file.
After reading the DTD file above, the program will ask for input from the user in order to begin creating an XML tree:
Lets create cd_collection...
What is the title attribute of album 1? Barenaked Ladies Are Men [enter]
What is the artist attribute of album 1? Barenaked Ladies [enter]
What is the label attribute of album 1? Raisin Records [enter]
Does album 1 disc 1 contain track(s) (y/n)? yes [enter]
What is the title attribute of album 1 disc 1 track 1? [enter]
Error: this attribute is required.
What is the title attribute of album 1 disc 1 track 1? Serendipity [enter]
What is the length attribute of album 1 disc 1 track 1 (optional)? 4:11 [enter]
What is the featuring attribute of album 1 disc 1 track 1 (optional)? [enter]
What is the title attribute of album 1 disc 1 track 2? Something You'll Never Find [enter]
What is the length attribute of album 1 disc 1 track 2 (optional)? 4:57 [enter]
What is the featuring attribute of album 1 disc 1 track 2 (optional)? [enter]
...
Does album 1 contain another disc (y/n)? [enter]
Error: Yes or No answer expected.
Does album 1 contain another disc (y/n)? n [enter]
Does cd_collection contain another album (y/n)? yes [enter]
What is the title attribute of album 2? Live From Mars [enter]
What is the artist attribute of album 2? Ben Harper [enter]
What is the label attribute of album 2? Virgin Records [enter]
Does album 1 disc 1 contain track(s) (y/n)? y [enter]
What is the title attribute of album 2 disc 1 track 1? Glory & Consequence [enter]
What is the length attribute of album 2 disc 1 track 1 (optional)? [enter]
What is the featuring attribute of album 2 disc 1 track 1 (optional)? [enter]
...
Does album 2 contain another disc (y/n)? y [enter]
...
What is the title attribute of album 2 disc 2 track 6? The Drugs Don't Work [enter]
What is the length attribute of album 2 disc 2 track 1 (optional)? [enter]
What is the featuring attribute of album 2 disc 2 track 1 (optional)? Richard Ashcroft [enter]
...
Does album 2 contain another disc (y/n)? no [enter]
Does cd_collection contain another album (y/n)? n [enter]
Ok! cd_collection saved in ./cd_collection.xml (or outputted to the screen, etc).
So you see, based on the DTD, the program asks for all pieces of data necessary to create an XML document. The program follows a pattern:
- It starts at the top of the tree (that the user supposedly has in his
imagination, a CD Collection in this case) and travels down the tree
in preorder fashion. - Elements labeled with a "+" are required at least once, elements with
a "*" are required zero or more times, elements with a "?" are
required zero or one times, and elements with no such label are
required exactly once. For the purpose of this description, i will
call these labels "quantity labels" - When the program arrives at an element of level X for the first time
on its way to the end of the first branch of the tree, it does one of
four things depending on the aforementioned labels: If the element's
label is a "+" or nothing, then it is assumed that the element is
required and moves on to obtain attribute data for the said element
or moves on to the next element if there are no attribute values to
prompt for. If the element's label is "*" or "?", then the program
asks the user if such an element exists. If yes, then the program
creates the element and prompts for attribute values if necessary,
before moving on. If no, then the program jumps to the next type of
element at level X if any, or else moves back up the tree to continue
preorder. If the element at level X is a final element that contains
#CDATA or #PCDATA (etc), then the program prompts for such data, or
leaves the element as EMPTY if necessary. Essentially, elements and
absolute data points are created in preorder. - When the program jumps back up the tree to a root of a branch, the
program analyzes the quantity labels once again. If the root element
at level X-1 has a label of "+" or "*", the program asks if more of
such elements exist (are to be entered, recorded, created, etc). This
is the mechanism by which the program discovers branches to traverse
in preorder. Elements at level X-1 who are roots of level-X elements
that contain a "?" label or nothing are not checked because they can
only exist in a quantity of at most one, so their presence (or
non-presence) is already determined as the program traverses down the
tree (away from root) as described in the previous step.
The program continues like this (with more DTD rules that I may have missed applied as necessary) until it finally gets back to the root element (cd_collection in this case), at which point the program has enough information to write an XML file containing all the aquired datat.
[/end imagination]
In that imaginary scenario, the example was a command line program. However, it could also be a graphical web interface. For example, instead of prompting for data piece by piece like this:
What is the title attribute of album 2? Live From Mars [enter]
What is the artist attribute of album 2? Ben Harper [enter]
What is the label attribute of album 2? Virgin Records [enter]
it could be obtained in an HTML form like this:
album 2:
title: ____Live From Mars____
artist: ____Ben Harper _______
label: ____Virgin Records ___
[submit button]
Does any such program (or similar program) exist, preferably free? And if so, what is it called and where can I find it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@trusktr:有一个选项可以在 websphere studio 中从 DTD 生成 HTML 表单。请参阅 链接
已更新以提供更多信息:
Websphere studio 已更名为 IBM Rational 应用程序开发人员,您可以从 此处。该IDE基于eclipse工作台。下载前请检查系统要求。
一旦安装,它就会有很多 XML 工具/编辑器。根据您的需要,您只需使用 DTD 编辑器创建 DTD,方法是转到菜单:文件 >新的>其他> XML> DTD
创建 DTD 后,单击 DTD >生成 HTML 表单。
@trusktr: there is an option to generate HTML form out of DTD in websphere studio. See link
updated to provide more information:
Websphere studio is renamed IBM Rational application developer, you can download the trial from here. This IDE is based on eclipse workbench. Do check system requirements before downloading.
Once installed, it got lot of XML tools/editiors. For your need, you just need to create a DTD using DTD editior by going menu : File > New > Other > XML > DTD
and once DTD is created, click DTD > Generate HTML Form.
您应该查看 Altova 套件。您可以使用 XMLSpy 来处理 XML 和 DTD。您可以使用 StyleVision 创建表单并输出 XML 数据。
祝你好运!!
You should check out the Altova suite. You can use XMLSpy to work with the XML and DTD's. You can use StyleVision to create the forms and output the XML data.
Good luck!!
Symfony Admin Generator 将为您创建功能性 Web 表单(带验证)。
http://www.symfony-project.org/jobeet/1_4/Propel /en/12
您可以使用 DTD 解析器和 XML to RDMS 将 DTD 转换为 SQL 架构(链接如下)。
http://www.rpbourret.com/xmldbms/index.htm
http://www.rpbourret.com/dtdparser/index.htm
然后,一次你有 SQL 模式,你可以将模式插入到 MySQL 中。然后,您可以使用 symfony pake 任务从现有 MySQL 数据库构建 schema.xml(或 schema.yml)文件:
./symfony propel:build-schema
一旦您拥有了可用的 schema.yml (或 schema.xml),您最终可以通过运行以下命令为数据库构建 Web 表单:
./symfony propel:generate-admin (完整详细信息在上面的第一个链接中)
建议使用 XSD DTD,但我理解你的情况。此外,XMLSpy 对于任何严肃或重复使用 XSD、XML 或 DTD 的工作来说都是非常棒的。
希望有帮助...
The Symfony Admin Generator will create functioning web forms (with validation) for you.
http://www.symfony-project.org/jobeet/1_4/Propel/en/12
You can use the DTD parser and XML to RDMS to convert the DTD into SQL schema (links below).
http://www.rpbourret.com/xmldbms/index.htm
http://www.rpbourret.com/dtdparser/index.htm
Then, once you have the SQL schema, you can insert the schema into MySQL. Then, you can build a schema.xml (or schema.yml) file from the existing MySQL database with the symfony pake task:
./symfony propel:build-schema
Once you have a working schema.yml (or schema.xml), you can finally build the web forms for your database by running:
./symfony propel:generate-admin (full details on in the first link, above)
Recommend using XSDs over DTDs, but I understand your situation. Also XMLSpy is totally awesome for any serious or repeated work with XSDs, XML or DTDs.
Hope that helps...