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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:14:40+00:00 2026-06-10T12:14:40+00:00

I have an string, and I want to do some things with it if

  • 0

I have an string, and I want to do some things with it if it is a valid XML; and If not, tell the user that the string is not a valid XML.

My code is this:

try 
{

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(rawData);

    //And here I want to do some things with doc if it is a valid XML.
}
catch
{
    //Tell the user that the string is not a valid XML.
}

Now, If rawData contains a valid XML data, there is no problem. Also if rawData contains something else (like HELLOEVERYBODY!), It will throw an exception, So I can tell the user the string is not a valid XML.

But When rawData contains a HTML page, The process takes a long time (more than 20 seconds!)…

It may differ from page to page. for example, it can process stackoverflow.com quickly, but processing 1pezeshk.com takes a long long time…

Isn’t there any faster way to validate XML before loading it into a XmlDocument?

  • 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-10T12:14:42+00:00Added an answer on June 10, 2026 at 12:14 pm

    I’ve seen this before and the problem is that XmlDocument tries to download the DTD for the document. In your sample this is http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd which lets you open a connection but never returns anything. So a simple solution (without any type of error checking mind you) is to remove anything before the -tag like this.

    WebClient wc = new WebClient();
    wc.Encoding = Encoding.UTF8;
    string data = wc.DownloadString("http://1pezeshk.com/");
    data = data.Remove(0, data.IndexOf("<html"));
    XmlDocument xml = new XmlDocument();
    xml.LoadXml(data);
    

    Edit

    Browsing to http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd actully returns the DTD, but it took well over a minute to respond. Since you still won’t do DTD-validation you should really just strip this from your HTML and then try to validate it as HTML.

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

Sidebar

Related Questions

suppose I have this string: some striinnngggg <a href=something/some_number>linkk</a> soooo <a href=someotherthing/not_number>asdfsadf</a> I want
HI, I have some string from XML file, and I I want to replace
I have some double values I want to convert to a string with this
Just some example code here, but I have lists of strings that I want
I have some code that gives a user id to a utility that then
I have a String with some value. I want to iterate over all classes
I have a folder full of files and I want to search some string
I have some html extracted to a string var, and want to then use
I have a string containing a valid Clojure form. I want to replace a
I have this code structure: public abstract class ContentEntryBase { public string UniqueIdentifier; public

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.