Csharp/C Sharp by API/System.Xml.Schema/XmlSchema — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:08, 26 мая 2010
XmlSchema.Compile
<source lang="csharp"> using System; using System.IO; using System.Xml.Schema; public class ValidateSchema {
public static void Main(string [] args) { ValidationEventHandler handler = new ValidationEventHandler(ValidateSchema.Handler); XmlSchema schema = XmlSchema.Read(File.OpenRead(args[0]),handler); schema.rupile(handler); } public static void Handler(object sender, ValidationEventArgs e) { Console.WriteLine(e.Message); }
}
</source>
XmlSchema.Write
<source lang="csharp"> using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Xml; using System.Xml.Schema; using System.Xml.Linq; public class MainClass {
public static void Main() { XDocument xDocument = new XDocument( new XElement("Books", new XElement("Book", new XAttribute("type", "Author"), new XElement("FirstName", "A"), new XElement("LastName", "B")), new XElement("Book", new XAttribute("type", "Author"), new XElement("FirstName", "C"), new XElement("LastName", "D")))); Console.WriteLine(xDocument); xDocument.Save("bookparticipants.xml"); XmlSchemaInference infer = new XmlSchemaInference(); XmlSchemaSet schemaSet = infer.InferSchema(new XmlTextReader("bookparticipants.xml")); XmlWriter w = XmlWriter.Create("bookparticipants.xsd"); foreach (XmlSchema schema in schemaSet.Schemas()) { schema.Write(w); } w.Close(); XDocument newDocument = XDocument.Load("bookparticipants.xsd"); Console.WriteLine(newDocument); }
}
</source>