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 8824125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:31:45+00:00 2026-06-14T06:31:45+00:00

I am trying to validate an xml file via a .dtd. I have write

  • 0

I am trying to validate an xml file via a .dtd. I have write this validator:

    public bool Validation(XmlDocument xmlDoc)
    {
        var xml = XmldocToString(xmlDoc);
        var r = new XmlTextReader(new StringReader(xml));
        var settings = new XmlReaderSettings();
        var sb = new StringBuilder();
        settings.ProhibitDtd = false;
        settings.ValidationType = ValidationType.DTD;
        settings.ValidationEventHandler += (a, e) =>
        {
            sb.AppendLine(e.Message);
            _isValid = false;
        };
        XmlReader validator = XmlReader.Create(r, settings);
        while (validator.Read())
        {
        }
        validator.Close();

        return _isValid;
    }

The problem is that I must have the dtd file in bin directory of the Solution. I want to chose a diferent directory to keep the .dtd file and i really can’t find how.

Thank you for your time.

  • 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-06-14T06:31:47+00:00Added an answer on June 14, 2026 at 6:31 am

    Declare in the Xml file the association with the DTD:

    Example in case the dtd is stored in a remote server:

    <!DOCTYPE Catalog PUBLIC "abc/Catalog" "http://xyz.abc.org/dtds/catalog.dtd">
    

    Take a look at that wiki page and at that site for more options and information about Xml files and DTD association.

    Example in case the dtd is placed locally (SYSTEM):

    How to reference a DTD from a document:

    Assuming the top element of the document is spec and the dtd is placed
    in the file mydtd in the subdirectory dtds of the directory from where
    the document were loaded
    :

    <!DOCTYPE spec SYSTEM "dtds/mydtd">
    

    Notes:

    The system string is actually an URI-Reference (as defined in RFC
    2396) so you can use a full URL string indicating the location of your
    DTD on the Web. This is a really good thing to do if you want others
    to validate your document. It is also possible to associate a PUBLIC
    identifier (a magic string) so that the DTD is looked up in catalogs
    on the client side without having to locate it on the web. A DTD
    contains a set of element and attribute declarations, but they don’t
    define what the root of the document should be. This is explicitly
    told to the parser/validator as the first element of the DOCTYPE
    declaration.

    (Excerpt from here)

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

Sidebar

Related Questions

I was trying to validate an XML signature. The validation according to this tutorial
I have this XML of products which I'm trying to validate. (i keep it
I was trying to validate this XML file ... where if <tag1> is Y
I have been trying to validate XML file using schema file in my C
I'm using Java 5 javax.xml.validation.Validator to validate XML file. I've done it for one
Im trying to validate my XML file with an external DTD. But I get
I have an XML file that I'm trying to validate against an XSD file
I'm trying to write a validation script that will validate XML against the NITF
I am trying to validate some XML via lxml and an xsd (ogckml22.xsd). This
I'm trying to validate a simple XML file against an XML schema using the

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.