Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Generating a DTD from an XML file is something I've not seen done quite often -- one of the main reasons being that <strong>you cannot be sure the XML file you used to generate the DTD will contain everything that the DTD should define</strong>.</p> <p>i.e. the generated DTD will only contain the elements and attributes that were present in that specific XML file <em>-- which doesn't necessarily means all elements and attributes that should be accepted when using it later</em>.</p> <p><br> That being said, I haven't found any PHP tool to create a DTD from an XML file... </p> <p>... But I've found a JAVA one : <strong><a href="http://saxon.sourceforge.net/dtdgen.html" rel="nofollow noreferrer">DTDGenerator - A tool to generate XML DTDs</a></strong> <em>(quoting)</em> :</p> <blockquote> <p>DTDGenerator is a program that <strong>takes an XML document as input and produces a Document Type Definition (DTD) as output</strong>.</p> <p>The aim of the program is to give you a quick start in writing a DTD. <br>The DTD is one of the many possible DTDs to which the input document conforms. <br>Typically you will want to examine the DTD and edit it to describe your intended documents more precisely.</p> </blockquote> <p><br> A couple of nice things about this <code>DTDGenerator</code> program are :</p> <ul> <li>There are some explanations on the website about the basic ideas of how this works</li> <li>The source code is provided</li> <li>It's only less that 600 lines long <ul> <li>which means one should be able to understand without too much efforts</li> <li>and <strong>possibly port it to PHP</strong> ?</li> <li>And there are some comments in the source code <em>-- which would help</em>.</li> </ul></li> <li>It's published under <a href="http://www.mozilla.org/MPL/MPL-1.0.html" rel="nofollow noreferrer">MPL</a> <em>-- which means open source ; which is good, if you want to port it</em></li> </ul> <p><br> Starting from that program's source code, it should be possible to write some PHP code <em>(if you cannot execute JAVA, and really need this to be written in PHP)</em> to do the same thing : the basic ideas are not that hard :</p> <ul> <li>You have to go through the XML structure</li> <li><strong>building a tree-representation of it</strong>, on each starting tag <ul> <li>which means elements</li> <li>that can have attributes</li> </ul></li> <li>And, when you've finished going through the XML document, you have to build the DTD from your reprensentation of the document <ul> <li>That might be the hard part -- looking at the source of the JAVA tool I linked to, it reprensents quite a large number of lines of code ^^</li> </ul></li> </ul> <p>Nice thing of taking a look at this <strong><a href="http://saxon.sourceforge.net/dtdgen.html" rel="nofollow noreferrer"><code>DTDGenerator</code></a></strong> before starting is that its author already thought about this process -- and already <strong>identified some situations that you might not think about</strong> ;-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload