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?