Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 7th, 2006, 11:30 AM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdamPengelly
Default XML Validation

Guys/Gals,

I have a XmlDocument object (not yet written to a physical file). This XmlDocument has a DTD specified in the <!DocType> Tag.

Can I validate this XmlDocument object against the DTD before it is physically written? And how would I go about this?

Kind regards

Adam
 
Old September 7th, 2006, 12:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Wont XmlDocument.Validate help in any way.

Regards
Ankur
 
Old September 7th, 2006, 07:57 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Take a look at these links:

  How To Validate an XML Document by Using DTD, XDR, or XSD in Visual C# .NET:
    Use the DTD to Validate the XML Document: http://support.microsoft.com/kb/307379/

  A DTD Tutorial: http://www.w3schools.com/dtd/default.asp

- Adam Kahtava [http://adam.kahtava.com]
 
Old September 8th, 2006, 03:16 AM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to AdamPengelly
Default

OK, i'm a step closer now...

------------------------------------
public bool ValidateXML() {
   objXml.Validate(ValidationEventHandler);
   return true;
}
void ValidationEventHandler(object sender, ValidationEventArgs e) {
   Error = e.Message;
}
-----------------------------------
Seems to be trying to validate the XML against the DTD, but I receive the exception below now:

"The XmlSchemaSet on the document is either null or has no schemas in it. Provide schema information before calling Validate. "

But the XmlDocumentType is definately declared and implements on the objXml before the validation is attempted. Any ideas?

Thanks so far, Adam

 
Old September 8th, 2006, 06:36 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you post more code?
What version of the .Net framework are you using?
Is the DTD declared in your XML file? e.g. <!DOCTYPE Product SYSTEM "Product.dtd">
Are you using an XmlValidatingReader? If so did you set the ValidationType to DTD? e.g. ValidationType.DTD;

This code snippet may be of use:

           // Validate the XML file with the DTD
            myXmlTextReader = new XmlTextReader (args[0]);
            myXmlValidatingReader = new XmlValidatingReader(myXmlTextReader);
            myXmlValidatingReader.ValidationType = ValidationType.DTD;
            Validate();

See the complete source here: http://samples.gotdotnet.com/quickst...gXML.cs&font=3

- Adam Kahtava [http://adam.kahtava.com]





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML validation with XSD ksskumar XML 0 October 12th, 2007 04:46 AM
XML validation error alz6z XML 1 May 3rd, 2007 11:06 AM
xml validation with xsd amolkad XML 0 June 24th, 2004 06:02 AM
XML Validation June XML 5 February 17th, 2004 11:41 AM
xml validation error kreddy XML 0 August 20th, 2003 12:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.