Posted By: Red5 | Aug 22nd, 2008 @ 9:46 AM
page 1 of 1
Comments: 2 | Views: 1123
Red5
Red5
Systems Manager Curmudgen
1. we receive an XSD from a client as a definition of data we should return to them in XML format
2. database person generates an XML file based on that XSD in SQL Server 2005.
3. QA needs to validate the XML file against the XSD to ensure we're doing the right things with the XML file

What do you use to accomplish such things? Is there a 3rd party toolset most of the industry uses? Or do most roll their own?

XML stuff has been off the radar for our little company and we have rarely dealt with it until recently. I've found some code on the web to use in VS to try and fulfill this need, but get conflicting results.
Also, is there a "best" way to declare an XSD in the first few lines of XML so it self-validates? I've noticed you can do this with a DTD.
I'm still researching all this but thought some of you can share your opinions here too...
section31
section31
OutOfCoffeeException
With few lines of code, you can write your own validator:

XmlDocument xd = new XmlDocument();
try
{
    xpd.LoadXml("<put your xml here/>");
}
catch (XmlException xEx)
{
        Console.WriteLine( "Invalid xml");
}
  
ValidationEventHandler validationHndl = new ValidationEventHandler(SchemaValidationHandler);
xpd.Schemas.Add(http://www.putyournamespace.here", pathToYourSchema.xsd);
xpd.Validate(validationHndl);


private void SchemaValidationHandler(object sender, ValidationEventArgs e)
{
        Debug.WriteLine("Schema Validation Error: {0}", e.Message);
}

I am not sure if this is a manually validation, or ir you want it to be executed in code.. But to do it manuall:
If you got the .xsd in Solution Explorer and right click it you got options like :
Validate Schema
Validate Instance
Generate Instance

What you want to use is the Validate Instance. to validate your specific xml this xml but be added as the  "Input Insance Filename". (right click -> properties on the xsd)

ps: i think i got these options since i have installed biztalk, and the xsd is inside a biztalk project.
page 1 of 1
Comments: 2 | Views: 1123
Microsoft Communities