3

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?

Wivani
  • 2,036
  • 22
  • 28
trusktr
  • 44,284
  • 53
  • 191
  • 263
  • 1
    I could suggest something else: create XSD instead of DTD, use LinqToXSD to generate classes, then use WPF PowerToys (from Karl Shiffletts website) to create forms/windows in WPF. – kubal5003 Sep 03 '11 at 13:58
  • Thanks, but I'm in an XML class at school and we're using XML and DTD. hehe – trusktr Sep 08 '11 at 01:03
  • I'll have to check that out though kubal! – trusktr Sep 09 '11 at 01:10
  • If this is a school assignment, was the task to find a free/open source solution to do this? Or do you need to apply a specific technology to go from the dtd to a form yourself? – Wivani Sep 15 '11 at 14:23

3 Answers3

3

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!!

pmartin
  • 2,731
  • 1
  • 25
  • 30
  • fyi: StyleVision is not free, but Authentic to use the templates afterwards – Arne Burmeister Sep 08 '11 at 20:43
  • Thanks pmartin... Altova looks like it could be a solution. I'm looking, preferably, for a free solution if possible though. I've also added much more detail to my question, see above! – trusktr Sep 09 '11 at 00:14
3

@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.

ag112
  • 5,537
  • 2
  • 23
  • 42
  • Hmmmm.... I wonder which product trial to download for that. There's a huge list here: http://www.ibm.com/developerworks/websphere/downloads/ – trusktr Sep 09 '11 at 21:02
1

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...

Homer6
  • 15,034
  • 11
  • 61
  • 81
  • So the end result is that the data is collected from the forms into the MySQL db right? I'd like the result to be XML though. Will I be able to end with an XML file in the end? – trusktr Sep 23 '11 at 23:24
  • Output directly from mysql http://stackoverflow.com/questions/2847674/xml-output-from-mysql/7600866#7600866 or you can create it with PHP, which is more flexible. See https://github.com/homer6/altumo/blob/master/source/php/Xml/XmlElement.md – Homer6 Sep 29 '11 at 17:40