*/
Got something to write about? Check out our Article Builder.

Other Views

corner
*/

XML FAQ - Testing Form Using .Net API

How do I test if XML is well formed using .Net API?

Well-formed means – The XML code must be syntactically correct or the XML parser will raise an error. However it still may not be ‘Valid’ especially if it has a schema associated with it. If you want to just test for Well-formed xml without testing for validity, there is no API for doing this except to encapsulate the code in try-catch which will automatically throw an exception if the xml is not Well-Formed. Here is a simple example:

XmlTextReader reader = new XmlTextReader(...);
try 
{
   while (reader.Read());
  //XML is ok
} 
catch (Exception e) 
{
  //Malformed XML            }


Otherwise the XmlValidatingReader class can be used to test both for Well-Formed XML and Valid XML.

Back to XML FAQ
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.