Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old October 7th, 2008, 09:39 PM
Member
 
Join Date: Mar 2007
Posts: 101
Default Validating XML file through an external DTD......C#

someone please help me do this...how to validate an xml file if the doctype is NOT specified! I have the DTD with me, but the I have to check XML files without the DOCTYPE or DTD

I already have to code to check when the DTD is specified but its gettting really confusing when the DTD is not specified. So please, someone help me achieve that.

Also, is there a way to get the root-element before i began anything? i ask because i want element names to be case insensitive

Expand|Select|Wrap|Line Numbers
  1. XmlReaderSettings settings = new XmlReaderSettings();
  2.                 settings.ProhibitDtd = false;
  3.                 settings.ValidationType = ValidationType.DTD;
  4.  
  5.                 settings.ValidationEventHandler += new ValidationEventHandler(MyValidationEventHandler);
  6.  
  7.                 // Create the XmlReader object.
  8.                 XmlReader reader = XmlReader.Create(xmlFile, settings);
  9.  
  10.                 // Parse the file. 
  11.                 while (reader.Read()) ;
  12.  
  13.                 if (isValid)
  14.                 {
  15.                     Console.WriteLine("XML is VALID ");
  16.                 }
  17.  
  18.  
  19.     static void MyValidationEventHandler(object sender, ValidationEventArgs args)
  20.     {
  21.         isValid = false;
  22.         Console.WriteLine("\nINVALID XML: " + args.Message);
  23.     }
  24.  
  25.  
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles