Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Note: <a href="http://msdn.microsoft.com/en-us/magazine/ee335713.aspx" rel="noreferrer">XML validation</a> could be subject to the <a href="http://en.wikipedia.org/wiki/Billion_laughs" rel="noreferrer">Billion Laughs</a> attack, and similar DoS vectors.</p> <p>This essentially does what rojoca mentioned in his comment:</p> <pre><code>&lt;?php $xml = &lt;&lt;&lt;END &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!DOCTYPE foo SYSTEM "foo.dtd"&gt; &lt;foo&gt; &lt;bar&gt;baz&lt;/bar&gt; &lt;/foo&gt; END; $root = 'foo'; $old = new DOMDocument; $old-&gt;loadXML($xml); $creator = new DOMImplementation; $doctype = $creator-&gt;createDocumentType($root, null, 'bar.dtd'); $new = $creator-&gt;createDocument(null, null, $doctype); $new-&gt;encoding = "utf-8"; $oldNode = $old-&gt;getElementsByTagName($root)-&gt;item(0); $newNode = $new-&gt;importNode($oldNode, true); $new-&gt;appendChild($newNode); $new-&gt;validate(); ?&gt; </code></pre> <p>This will validate the document against the <code>bar.dtd</code>.</p> <p>You can't just call <code>$new-&gt;loadXML()</code>, because that would just set the DTD to the original, and the <code>doctype</code> property of a DOMDocument object is read-only, so you have to copy the root node (with everything in it) to a new DOM document.</p> <p>I only just had a go with this myself, so I'm not entirely sure if this covers everything, but it definitely works for the XML in my example.</p> <p>Of course, the quick-and-dirty solution would be to first get the XML as a string, search and replace the original DTD by your own DTD and then load it.</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.
 

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