是否有程序或脚本通过接收用户通过基于此类DTD模式的表单输入来从DTD模式(免费)生成XML模型?

时间:2011-09-03 11:27:46

标签: xml xsd dtd

我想知道是否存在可以读取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(等),然后程序提示输入此类数据,或 如有必要,将元素保留为EMPTY。基本上,元素和 绝对数据点是按预先创建的。
  • 当程序将树跳回到分支的根目录时, 程序再次分析数量标签。如果是根元素 在级别X-1的标签为“+”或“*”,程序会询问是否有更多 存在这样的元素(将被输入,记录,创建等)。这个 是程序发现分支遍历的机制 在预订。级别为X-1的元素是级别X元素的根 包含“?”标签或没有任何未检查,因为他们可以 只存在于最多一个,所以他们的存在(或 当程序遍历时,已经确定不存在 树(远离根),如上一步所述。

程序继续这样(根据需要我可能错过了更多的DTD规则),直到它最终返回到根元素(在这种情况下为cd_collection),此时程序有足够的信息来编写XML包含所有获取数据的文件。

[/ end imagination]

在那个想象的场景中,示例是一个命令行程序。但是,它也可以是图形Web界面。例如,不是像这样一块一条地提示数据:

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]

是否存在任何此类程序(或类似程序),最好是免费的?如果是这样,它叫什么,我在哪里可以找到它?

3 个答案:

答案 0 :(得分:3)

您应该查看Altova suite。您可以使用XMLSpy来处理XML和DTD。您可以使用StyleVision创建表单并输出XML数据。

祝你好运!!

答案 1 :(得分:3)

@trusktr:可以选择在websphere studio中使用DTD生成HTML表单。见link

已更新,以提供更多信息:

Websphere studio更名为IBM Rational应用程序开发人员,您可以从here下载试用版。此IDE基于eclipse工作台。下载前请检查系统要求。

一旦安装,就会有很多XML工具/编辑器。根据您的需要,您只需要通过菜单使用DTD editior创建DTD:文件&gt;新&gt;其他&gt; XML&gt; DTD  并且一旦创建了DTD,请单击DTD&gt;生成HTML表单。

答案 2 :(得分:1)

Symfony Admin Generator将为您创建功能正常的Web表单(带验证)。

http://www.symfony-project.org/jobeet/1_4/Propel/en/12

您可以使用DTD解析器和XML到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 (上面第一个链接的完整详情)

建议在DTD上使用XSD,但我了解您的情况。对于使用XSD,XML或DTD的任何严肃或重复的工作,XMLSpy也非常棒。

希望有帮助...

相关问题