-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Rama_Pallavi
Message 2 in Discussion

Hi Elan,      This solution may give you an idea of how you can write XSD for your 
sample example code.     Books.xsd    
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns="urn:bookstore-schema" 
elementFormDefault="qualified" targetNamespace="urn:bookstore-schema"> 
<xsd:element name="bookstore" type="bookstoreType" /> 
<xsd:element name="comment" type="xsd:string" /> 
<xsd:element name="author" type="authorName"/> 
<xsd:complexType name="authorName"> 
<xsd:sequence> 
<xsd:element name="first-name" type="xsd:string" /> 
<xsd:element name="last-name" type="xsd:string" /> 
</xsd:sequence> 
</xsd:complexType> 
<xsd:complexType name="bookstoreType"> 
<xsd:sequence maxOccurs="unbounded"> 
<xsd:element name="book" type="bookType" /> 
<xsd:element ref="comment" minOccurs="0" /> 
</xsd:sequence> 
</xsd:complexType> 
<xsd:complexType name="bookType"> 
<xsd:sequence> 
<xsd:element name="title" type="xsd:string" /> 
<xsd:element ref="author" /> 
<xsd:element name="price" type="xsd:decimal" /> 
</xsd:sequence> 
<xsd:attribute name="genre" type="xsd:string" /> 
</xsd:complexType> 
 
</xsd:schema> 
C# Create a console Application copy this code 
using System; 
using System.Xml; 
using System.Xml.Schema; 
namespace XMLSchemaValidation 
{ 
/// <summary> 
/// Summary description for Class1. 
/// </summary> 
class Class1 
{ 
/// <summary> 
/// The main entry point for the application. 
/// </summary> 
System.Boolean m_success; 
[STAThread] 
static void Main(string[] args) 
{ 
//  
// TODO: Add code to start application here. 
//  
XmlValidatingReader reader = null; 
XmlSchemaCollection myschema = new XmlSchemaCollection(); 
ValidationEventHandler eventHandler = new 
ValidationEventHandler(Class1.ShowCompileErrors ); 
  
try 
{ 
//Create the XML fragment to be parsed. 
String xmlFrag = "<author xmlns='urn:bookstore-schema' 
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" + 
"<first-name>Herman</first-name>" + 
"<last-name>Melville</last-name>" + 
"</author>"; 
//Create the XmlParserContext. 
XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); 
 
//Implement the reader.  
reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context); 
//Add the schema. 
myschema.Add("urn:bookstore-schema", "Books.xsd"); 
//Set the schema type and add the schema to the reader. 
reader.ValidationType = ValidationType.Schema; 
reader.Schemas.Add(myschema); 
while (reader.Read()) 
{ 
} 
 
Console.WriteLine("Completed validating xmlfragment"); 
} 
catch (XmlException XmlExp) 
{ 
Console.WriteLine(XmlExp.Message); 
} 
catch(XmlSchemaException XmlSchExp) 
{ 
Console.WriteLine(XmlSchExp.Message); 
} 
catch(Exception GenExp) 
{ 
Console.WriteLine(GenExp.Message); 
} 
finally 
{ 
Console.Read(); 
} 
} 
public static void ShowCompileErrors(object sender, ValidationEventArgs args) 
{ 
Console.WriteLine("Validation Error: {0}", args.Message); 
} 
} 
} 
Note: Keep the Book.xsd in the Bin/Debug directory before you execute this program. 
If you look at the C# Code XML Fragment is forming as string if you want to save as a 
seperate xml file you can do that also. 
Regards, 
Ram 
  
  
 

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to