Re: Specifying a DTD for a DOMDocument



On Oct 23, 2:34 pm, bmic...@xxxxxxxxx wrote:
On Oct 23, 3:13 pm, ZeldorBlat <zeldorb...@xxxxxxxxx> wrote:





On Oct 23, 5:22 am, bmic...@xxxxxxxxx wrote:

Hey,

I'd like to specify the DTD file for a DOMDocument on creation; so I
can validate it.
The DTD file already exists (let's call it content.dtd)

$dom = new DOMDocument('1.0', 'utf-8');
// Do something here to link cotnent.dtd to the DOMDocument. How do I
do that?

// Form the xml document.
$dom->createElement('root_node');
...

I found through the php documentation that I can validate xml content
against a DTD if load the XML file (but not if I create it). Something
like that (assuming the xml content is in file content.xml which
specifies *<!DOCTYPE root_node SYSTEM "content.dtd">*):

$dom = new DOMDocument;
$dom->Load('content.xml');
if ($dom->validate()) {
// document is valid

}

See this:

<http://www.php.net/manual/en/function.dom-domimplementation-
createdocumenttype.php>

I tried this approach. The xml content is now formatted the way I want
to.
The problem though is that $dom->validate() is returning false
although the xml content is valid with respect to the DTD.
Seems that the validate() function only works when loading xml files.
Any thoughts?- Hide quoted text -

- Show quoted text -

load your dtd in a browser with the xml file. basic but works fast

.



Relevant Pages

  • Expat - how to UseForeignDTD
    ... This runs as expected but now I would like to load a DTD without ... I have done regular ExternalEntityRefHandlers before. ... xml file, but my _ExternalEntityRefHandler is never called. ...
    (comp.lang.python)
  • validating xml against DTD
    ... I am using the following code to validate an xml file ... against a DTD. ... I force the requirement to declare the DTD in the XML ... Private Function validate() As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Serializing from XML with remote DTD
    ... I have an XML file which I am serializing into a class using the ... the XML file has a dtd in it that points to a remote ... mean, it's not trying to validate it, so why ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Convert flat file to XML document
    ... >I am a newbee and have a comma seperated flat-file and a DTD. ... >XML file as per the the definition in the DTD. ... As required add extra processing to your program so that you can ... The ultimate truth is that there is no ultimate truth ...
    (microsoft.public.dotnet.languages.csharp)
  • How to get Java to read in XML file and parse it against DTD?
    ... When using Java to read in an XML file, ... the XML file to be parsed against the specified DTD. ... I have an existing Java application that allows users to modify values ...
    (comp.lang.java.programmer)