Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3304748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:05:42+00:00 2026-05-17T21:05:42+00:00

I have a big problem with the PHP DOMDocument::validate() who seems to ask the

  • 0

I have a big problem with the PHP DOMDocument::validate() who seems to ask the DTD systematically.

It is a big problem when I whant to validate, for example, an XHTML document as explained here.

As w3.org seems to reject all request from a PHP server, it’s impossible to validate my document with this method…

Is there any solution for that ?

Thanks by advance

[EDIT] Here is some precisions :

/var/www/test.php :

<?php
$implementation = new DOMImplementation();

$dtd = $implementation->createDocumentType
       (
         'html',                                     // qualifiedName
         '-//W3C//DTD XHTML 1.0 Transitional//EN',   // publicId
         'http://www.w3.org/TR/xhtml1/DTD/xhtml1-'
           .'transitional.dtd'                       // systemId
       );

$document = $implementation->createDocument('', '', $dtd);

$document->validate();

[http://]127.0.0.1/test.php :

Warning: DOMDocument::validate(http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
 in /var/www/test.php on line 14

Warning: DOMDocument::validate(): I/O warning : failed to load external entity "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" in /var/www/test.php on line 14

Warning: DOMDocument::validate(): Could not load the external subset "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" in /var/www/test.php on line 14

Related question :

  • How to import XML string in a php DOMDocument ? (solved)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:05:42+00:00Added an answer on May 17, 2026 at 9:05 pm

    Like pointed out in the comments, there is a Bug/FeatureRequest for DOMDocument::validate to accept the DTD as a string:

    • http://bugs.php.net/bug.php?id=48080

    You could host the DTD yourself and change the systemId accordingly or you can provide a custom stream context to any loading done through libxml. For instance, providing a UserAgent will get around the W3C’s blocking. You could also add proxy this way. See

    • libxml_set_streams_context() and
    • list of available HTTP context options

    Example:

    $di = new DOMImplementation;
    $dom = $di->createDocument(
        'html',
        'html',
        $di->createDocumentType(
            'html',
            '-//W3C//DTD XHTML 1.0 Transitional//EN',
            'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
        )
    );
    $opts = array(
        'http' => array(
            'user_agent' => 'PHP libxml agent',
        )
    );
    $context = stream_context_create($opts);
    libxml_set_streams_context($context);
    
    var_dump($dom->validate());
    

    This would output

    Warning: DOMDocument::validate(): Element html content does not follow the DTD, expecting (head , body), got  
    
    Warning: DOMDocument::validate(): Element html namespace name for default namespace does not match the DTD 
    
    Warning: DOMDocument::validate(): Value for attribute xmlns of html is different from default "http://www.w3.org/1999/xhtml" 
    
    Warning: DOMDocument::validate(): Value for attribute xmlns of html must be "http://www.w3.org/1999/xhtml" 
    
    bool(false)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using gettext in my PHP code, but I have a big problem.
I have a big problem. I have some applications made on an unix based
I have a big problem opening http://localhost/ on Windows 7 (beta). I installed this
Hey Guys, i have a big problem with my jQuery Datepicker Script. I use
I have big trouble with file uploads with php. My own tests are successful
I recently came across a big problem, as I have a system that's paying
I have had a few problems with log files growing too big on my
I have big issue with url-rewriting for IIS 7.0. I've written simple module for
How would you maintain the legacy applications that: Has no unit tests have big
I have a big string (let's call it a CSV file, though it isn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.