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

  • Home
  • SEARCH
  • 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 835973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:54:29+00:00 2026-05-15T04:54:29+00:00

I need to parse DTDs using PHP and am hoping there’s a simple library

  • 0

I need to parse DTDs using PHP and am hoping there’s a simple library to help out. Each DTD has numerous <!ENTITY... and <!-- Comment... elements, which I need to act upon.

Note that I do not need to validate anything against these DTDs, simply parse them as data files themselves.

A few options I’ve looked at:

James Clarke’s SD, which is an option of last resort, but I’d like to avoid the complexity of building/installing/configuring code external to PHP. I’m not sure it’s even possible in my situation.

PEAR has an XML_DTD_Parser, which requires installing/configuring PEAR and a number of pear modules, which I’m also not sure is possible, and would rather avoid. Has anyone used it with success? EDIT: I’ve since learned that XML_DTD_Parser discards comments, so is not a valid option for my needs.

PHP XML Classes has the class_path_parser, which another site suggested, but it fails to read ENTITY elements. It appears to be using PHP’s built in XML parsing capabilities, which use EXPAT.

PHP’s DOMDocument will validate against a DTD, so must be able to read them, though I don’t see how to get at the DTD parser directly at first glance.

  • 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-15T04:54:29+00:00Added an answer on May 15, 2026 at 4:54 am

    None of the standard XML parsers for PHP give access to general entities*, and few give access to comments. PHP’s built in XML Parser uses Expat, but does not expose the full expat API; in particular, a handler for entities cannot be set. There is a PHP bug filed to add this.

    AFAICT, the only way to handle comments and general entities in a DTD parser is to write your own parser; either by hand, or using one of the lexers and parser generators available for php (e.g. PHP_LexerGenerator and PHP_ParserGenerator among others).

    * PHP’s expat wrapper (XML Parser) does give access to notation declarations, which are similar to, but not the same as general entities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.