public static void XmlSchemaWriteNullWriter() { XmlSchema schema = new XmlSchema(); Assert.Throws <ArgumentNullException>(() => schema.Write(default(XmlWriter))); Assert.Throws <ArgumentNullException>(() => schema.Write(default(XmlWriter), namespaceManager: null)); }
static void Run(string [] args) { if (args.Length < 1) { Console.WriteLine("USAGE: mono dtd2xsd.exe instance-xmlfile [output-xsdfile]"); return; } XmlTextReader xtr; if (args [0].EndsWith(".dtd")) { xtr = new XmlTextReader("<!DOCTYPE dummy SYSTEM '" + args [0] + "'><dummy/>", XmlNodeType.Document, null); } else { xtr = new XmlTextReader(args [0]); } XmlSchema xsd = Dtd2Xsd.Run(xtr); if (args.Length > 1) { xsd.Write(new StreamWriter(args [1])); } else { xsd.Write(Console.Out); } }
public static void TestMain() { try { var readSettings = new XmlReaderSettings() { IgnoreComments = false }; XmlReader reader = XmlReader.Create("example.xsd"); XmlSchema myschema = XmlSchema.Read(reader, ValidationCallback); myschema.Write(Console.Out); FileStream file = new FileStream("writebackexample.xsd", FileMode.Create, FileAccess.ReadWrite); XmlWriterSettings writeSettings = new XmlWriterSettings() { Indent = true, OmitXmlDeclaration = false, NewLineOnAttributes = true }; XmlWriter xwriter = XmlWriter.Create(file, writeSettings); myschema.Write(xwriter); } catch (Exception e) { Console.WriteLine(e); } }
static void Main() { try { XmlTextReader readerDiagram = new XmlTextReader("archimate3_Diagram.xsd"); XmlSchema schemaDiagram = XmlSchema.Read(readerDiagram, ValidationCallback); schemaDiagram.Write(Console.Out); FileStream file = new FileStream("archimate3_Diagram-out.xsd", FileMode.Create, FileAccess.ReadWrite); XmlTextWriter xwriter = new XmlTextWriter(file, new UTF8Encoding()); xwriter.Formatting = Formatting.Indented; schemaDiagram.Write(xwriter); file.Close(); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("archimate3_Diagram.xsd: press enter to continue..."); Console.ReadLine(); try { XmlTextReader readerModel = new XmlTextReader("archimate3_Model.xsd"); XmlSchema schemaModel = XmlSchema.Read(readerModel, ValidationCallback); schemaModel.Write(Console.Out); FileStream file = new FileStream("archimate3_Model-out.xsd", FileMode.Create, FileAccess.ReadWrite); XmlTextWriter xwriter = new XmlTextWriter(file, new UTF8Encoding()); xwriter.Formatting = Formatting.Indented; schemaModel.Write(xwriter); file.Close(); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("archimate3_Model.xsd: press enter to continue..."); Console.ReadLine(); try { XmlTextReader readerView = new XmlTextReader("archimate3_View.xsd"); XmlSchema schemaView = XmlSchema.Read(readerView, ValidationCallback); schemaView.Write(Console.Out); FileStream file = new FileStream("archimate3_View-out.xsd", FileMode.Create, FileAccess.ReadWrite); XmlTextWriter xwriter = new XmlTextWriter(file, new UTF8Encoding()); xwriter.Formatting = Formatting.Indented; schemaView.Write(xwriter); file.Close(); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("archimate3_View.xsd: press enter to continue..."); Console.ReadLine(); }
// TODO: move these to XmlSchemaExtensions, add XmlDoc extensions if needed. Write a version not using a memorystream but maybe a stringbuilder instead for large schemas. public static async System.Threading.Tasks.Task <string> ToStringAsync(this XmlSchema schema, Encoding encoding) { var xmlWriterSettings = new XmlWriterSettings { Async = true, NewLineHandling = NewLineHandling.None }; var outputMemoryStream = new MemoryStream(); try { using (var stringWriter = new StreamWriter(stream: outputMemoryStream, encoding: encoding, bufferSize: 512, leaveOpen: true)) using (var xmlTextWriter = XmlWriter.Create(stringWriter, xmlWriterSettings)) using (var streamReader = new StreamReader(outputMemoryStream)) { schema.Write(xmlTextWriter); await xmlTextWriter .FlushAsync() .ConfigureAwait(continueOnCapturedContext: false); outputMemoryStream.Seek(0, SeekOrigin.Begin); return(await streamReader.ReadToEndAsync()); } } finally { if (outputMemoryStream != null) { outputMemoryStream.Dispose(); } } }
public async Task <IActionResult> UpdateDatamodel(string org, string app, string modelName) { SchemaKeywordCatalog.Add <InfoKeyword>(); try { modelName = modelName.AsFileName(); } catch { return(BadRequest("Invalid model name value.")); } string filePath = $"App/models/{modelName}"; using (Stream resource = Request.Body) { // Read the request body and deserialize to Json Schema using StreamReader streamReader = new StreamReader(resource); string content = await streamReader.ReadToEndAsync(); TextReader textReader = new StringReader(content); JsonValue jsonValue = await JsonValue.ParseAsync(textReader); JsonSchema jsonSchemas = new Manatee.Json.Serialization.JsonSerializer().Deserialize <JsonSchema>(jsonValue); // Create the directory if it does not exist string appPath = _repository.GetAppPath(org, app); string directory = appPath + Path.GetDirectoryName(filePath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } // Serialize and store the Json Schema var serializer = new Manatee.Json.Serialization.JsonSerializer(); JsonValue toar = serializer.Serialize(jsonSchemas); byte[] byteArray = Encoding.UTF8.GetBytes(toar.ToString()); MemoryStream jsonstream = new MemoryStream(byteArray); await _repository.WriteData(org, app, $"{filePath}.schema.json", jsonstream); // update meta data JsonSchemaToInstanceModelGenerator converter = new JsonSchemaToInstanceModelGenerator(org, app, jsonSchemas); ModelMetadata modelMetadata = converter.GetModelMetadata(); string root = modelMetadata.Elements != null && modelMetadata.Elements.Count > 0 ? modelMetadata.Elements.Values.First(e => e.ParentElement == null).TypeName : null; _repository.UpdateApplicationWithAppLogicModel(org, app, modelName, "Altinn.App.Models." + root); // Convert to XML Schema and store in repository JsonSchemaToXsd jsonSchemaToXsd = new JsonSchemaToXsd(); XmlSchema xmlschema = jsonSchemaToXsd.CreateXsd(jsonSchemas); MemoryStream xsdStream = new MemoryStream(); XmlTextWriter xwriter = new XmlTextWriter(xsdStream, new UpperCaseUtf8Encoding()); xwriter.Formatting = Formatting.Indented; xwriter.WriteStartDocument(false); xmlschema.Write(xsdStream); await _repository.WriteData(org, app, $"{filePath}.xsd", xsdStream); } return(Ok()); }
/// <summary> /// Converts the Schema object into a string /// </summary> private string SchemaToString(XmlSchema schema) { var sw = new StringWriter(); schema.Write(sw); return(sw.ToString()); }
public static String GetSchemaName(XmlSchema schema) { string name = null; using (MemoryStream mem = new MemoryStream()) { schema.Write(mem); mem.Flush(); mem.Position = 0; XmlReader reader = XmlReader.Create(mem); reader.MoveToContent(); while (reader.Read()) { if (reader.IsStartElement() && reader.LocalName == "simpleType") { name = reader.GetAttribute("name"); break; } if (reader.IsStartElement() && reader.LocalName == "element") { name = reader.GetAttribute("type"); break; } } reader.Close(); mem.Close(); } return(name); }
private static async Task TestFiles(string schemaPath, string expectedPath, string uri) { // Arrange JsonSchemaKeywords.RegisterXsdKeywords(); JsonSchemaToXmlSchemaConverter converter = new JsonSchemaToXmlSchemaConverter(new JsonSchemaNormalizer()); JsonSchema jsonSchema = await ResourceHelpers.LoadJsonSchemaTestData(schemaPath); XmlSchema expected = ResourceHelpers.LoadXmlSchemaTestData(expectedPath); // Act var schemaUri = new Uri(uri, UriKind.RelativeOrAbsolute); XmlSchema actual = converter.Convert(jsonSchema, schemaUri); StringBuilder xmlStringBuilder = new StringBuilder(); await using (XmlWriter xmlWriter = XmlWriter.Create(xmlStringBuilder, new XmlWriterSettings { Async = true, CheckCharacters = true, ConformanceLevel = ConformanceLevel.Document, Indent = true, Encoding = SafeUtf8, OmitXmlDeclaration = false })) { actual.Write(xmlWriter); } string xsd = xmlStringBuilder.ToString(); // Assert XmlSchemaAssertions.IsEquivalentTo(expected, actual); }
public void WriteXml(XmlWriter xmlWriter) { StringWriter textWriter = new StringWriter(CultureInfo.InvariantCulture); XmlTextWriter writer = new XmlTextWriter(textWriter); schema.Write(writer); writer.Flush(); UTF8Encoding utf8 = new UTF8Encoding(); byte[] wsdlText = utf8.GetBytes(textWriter.ToString()); XmlDictionaryReaderQuotas quota = new XmlDictionaryReaderQuotas(); quota.MaxDepth = 32; quota.MaxStringContentLength = 8192; quota.MaxArrayLength = 16384; quota.MaxBytesPerRead = 4096; quota.MaxNameTableCharCount = 16384; XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(wsdlText, 0, wsdlText.GetLength(0), null, quota, null); if ((reader.MoveToContent() == XmlNodeType.Element) && (reader.Name == "xs:schema")) { xmlWriter.WriteNode(reader, false); } reader.Close(); }
void GenerateXmlSchema(String[] formats, String fileFormatType) { StreamWriter writer = File.CreateText(xmlSchemaFile + "_" + fileFormatType + ".xml"); XmlSchema schema; XmlSchemaElement element; XmlSchemaComplexType complexType; XmlSchemaSequence sequence; schema = new XmlSchema(); element = new XmlSchemaElement(); schema.Items.Add(element); element.Name = "Table"; complexType = new XmlSchemaComplexType(); element.SchemaType = complexType; sequence = new XmlSchemaSequence(); complexType.Particle = sequence; element = new XmlSchemaElement(); element.Name = "Number"; element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(element); for (int i = 0; i < formats.Length; i++) { element = new XmlSchemaElement(); element.Name = formats[i]; element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(element); } schema.Compile(new ValidationEventHandler(ValidationCallbackOne)); schema.Write(writer); writer.Close(); }
public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:notation name="jpeg" public="image/jpeg" system="viewer.exe" /> XmlSchemaNotation notation = new XmlSchemaNotation(); notation.Name = "jpeg"; notation.Public = "image/jpeg"; notation.System = "viewer.exe"; schema.Items.Add(notation); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne); schemaSet.Add(schema); schemaSet.Compile(); XmlSchema compiledSchema = null; foreach (XmlSchema schema1 in schemaSet.Schemas()) { compiledSchema = schema1; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema.Write(Console.Out, nsmgr); }
private static string Schema_textxml(XmlSchema xmlSchema) { if (!xmlSchema.IsCompiled) { XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne); schemaSet.Add(xmlSchema); schemaSet.Compile(); } XmlWriterSettings settings = new XmlWriterSettings { Indent = true, Encoding = Encoding.UTF8 }; StringWriter strWriter = new StringWriter(); XmlWriter XmlWriter = XmlWriter.Create(strWriter, settings); xmlSchema.Write(XmlWriter); XmlWriter.Close(); return(strWriter.ToString()); //StringWriter strWriter = new StringWriter(); //xmlSchema.Write(XmlWriter); //return StringWriter.ToString(); }
public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:simpleType name="ZipCodeType"> XmlSchemaSimpleType ZipCodeType = new XmlSchemaSimpleType(); ZipCodeType.Name = "ZipCodeType"; // <xs:restriction base="xs:string"> XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction(); restriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:length value="5"/> XmlSchemaLengthFacet length = new XmlSchemaLengthFacet(); length.Value = "5"; restriction.Facets.Add(length); ZipCodeType.Content = restriction; schema.Items.Add(ZipCodeType); // <xs:element name="Address"> XmlSchemaElement element = new XmlSchemaElement(); element.Name = "Address"; // <xs:complexType> XmlSchemaComplexType complexType = new XmlSchemaComplexType(); // <xs:attribute name="ZipCode" type="ZipCodeType"/> XmlSchemaAttribute ZipCodeAttribute = new XmlSchemaAttribute(); ZipCodeAttribute.Name = "ZipCode"; ZipCodeAttribute.SchemaTypeName = new XmlQualifiedName("ZipCodeType", ""); complexType.Attributes.Add(ZipCodeAttribute); element.SchemaType = complexType; schema.Items.Add(element); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne); schemaSet.Add(schema); schemaSet.Compile(); XmlSchema compiledSchema = null; foreach (XmlSchema schema1 in schemaSet.Schemas()) { compiledSchema = schema1; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema.Write(Console.Out, nsmgr); }
public static void Main() { XmlSchema schema = new XmlSchema(); schema.ElementFormDefault = XmlSchemaForm.Qualified; schema.TargetNamespace = "http://www.w3.org/2001/05/XMLInfoset"; // <xs:import namespace="http://www.example.com/IPO" /> XmlSchemaImport import = new XmlSchemaImport(); import.Namespace = "http://www.example.com/IPO"; schema.Includes.Add(import); // <xs:include schemaLocation="example.xsd" /> XmlSchemaInclude include = new XmlSchemaInclude(); include.SchemaLocation = "example.xsd"; schema.Includes.Add(include); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); schemaSet.Add(schema); schemaSet.Compile(); XmlSchema compiledSchema = null; foreach (XmlSchema schema1 in schemaSet.Schemas()) { compiledSchema = schema1; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema.Write(Console.Out, nsmgr); }/* Main() */
public XmlSchema BuildSchema(TextWriter output) { var schema = new XmlSchema(); schema.Items.Add(Root()); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne); schemaSet.Add(schema); schemaSet.Compile(); XmlSchema compiledSchema = null; foreach (XmlSchema schema1 in schemaSet.Schemas()) { compiledSchema = schema1; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema.Write(output, nsmgr); return(compiledSchema); }
internal string GenerateTypedDataSet(XmlSchemaElement element, XmlSchemas schemas, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider) { if (element == null) { return(null); } if (this.importedTypes[element.SchemaType] != null) { return((string)this.importedTypes[element.SchemaType]); } IList list = schemas.GetSchemas(element.QualifiedName.Namespace); if (list.Count != 1) { return(null); } XmlSchema schema = list[0] as XmlSchema; if (schema == null) { return(null); } MemoryStream stream = new MemoryStream(); schema.Write(stream); stream.Position = 0L; DesignDataSource designDS = new DesignDataSource(); designDS.ReadXmlSchema(stream, null); stream.Close(); string str = TypedDataSetGenerator.GenerateInternal(designDS, compileUnit, mainNamespace, codeProvider, this.dataSetGenerateOptions, null); this.importedTypes.Add(element.SchemaType, str); return(str); }
/// <summary> /// OGC WFS DescribeFeatureType /// </summary> /// <param name="context"></param> private void ProcessDescribeFeatureType(HttpResponse response, StringDictionary parameters) { if (!String.IsNullOrEmpty(parameters[WfsParameters.OutputFormat]) && String.Compare(parameters[WfsParameters.OutputFormat], Declarations.GMLSFFormat) != 0) { SetResponseToServiceException(response, WfsExceptionCode.InvalidFormat, "Invalid OUTPUTFORMAT for DescribeFeatureType Request. Only " + Declarations.GMLSFFormat + "format is supported"); return; } byte[] featureTypeBytes = null; // Check if this is a WFS or WMS request and get the appropriate layers parameter string layers = parameters[WfsParameters.TypeName]; if (String.IsNullOrEmpty(layers)) { throw new WfsFault(WfsExceptionCode.LayerNotDefined); } ViewContext context = new ViewContext(parameters); XmlSchema schema = FeatureCollection.GetFeatureSchema(context, false); using (MemoryStream memoryStream = new MemoryStream()) { schema.Write(memoryStream); featureTypeBytes = memoryStream.ToArray(); } response.Clear(); response.ContentType = "text/xml"; response.OutputStream.Write(featureTypeBytes, 0, featureTypeBytes.Length); }
public async Task <IActionResult> UpdateDatamodel(string org, string app, string filepath) { SchemaKeywordCatalog.Add <InfoKeyword>(); using (Stream resource = Request.Body) { // Read the request body and deserialize to Json Schema using StreamReader streamReader = new StreamReader(resource); string content = await streamReader.ReadToEndAsync(); TextReader textReader = new StringReader(content); JsonValue jsonValue = await JsonValue.ParseAsync(textReader); JsonSchema jsonSchemas = new Manatee.Json.Serialization.JsonSerializer().Deserialize <JsonSchema>(jsonValue); // Serialize and store the Json Schema var serializer = new Manatee.Json.Serialization.JsonSerializer(); JsonValue toar = serializer.Serialize(jsonSchemas); byte[] byteArray = Encoding.UTF8.GetBytes(toar.ToString()); MemoryStream jsonstream = new MemoryStream(byteArray); await _repository.WriteData(org, app, $"{filepath}.schema.json", jsonstream); // Convert to XML Schema and store in repository JsonSchemaToXsd jsonSchemaToXsd = new JsonSchemaToXsd(); XmlSchema xmlschema = jsonSchemaToXsd.CreateXsd(jsonSchemas); MemoryStream xsdStream = new MemoryStream(); XmlTextWriter xwriter = new XmlTextWriter(xsdStream, new UpperCaseUtf8Encoding()); xwriter.Formatting = Formatting.Indented; xwriter.WriteStartDocument(false); xmlschema.Write(xsdStream); await _repository.WriteData(org, app, $"{filepath}.xsd", xsdStream); } return(Ok()); }
public void TestWriteFlags() { XmlSchema schema = GetSchema("Test/XmlFiles/xsd/2.xsd"); StringWriter sw = new StringWriter(); XmlTextWriter xtw = new XmlTextWriter(sw); schema.Write(xtw); }
void WriteSchema(string fileName, XmlSchema schema) { StreamWriter sw = new StreamWriter(fileName); schema.Write(sw); sw.Close(); Console.WriteLine("Written file " + fileName); }
public static string WriteSchema(XmlSchema s) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); s.Write(sw); return(sb.ToString()); }
// TODO: also move to .net std 1.1 helper public static string ToString(this XmlSchema schema, Encoding encoding) { using (var stringWriter = new EncodedStringWriter(encoding)) { schema.Write(stringWriter); return(stringWriter.ToString()); } }
public static bool SerializeToStream(IDocumentPlug plug, Stream outputStream) { bool result = true; XmlSchema schema = SerializeToXSD(plug); schema.Write(outputStream); return(result); }
static void Main() { try { XmlTextReader reader = new XmlTextReader("example.xsd"); XmlSchema myschema = XmlSchema.Read(reader, ValidationCallback); myschema.Write(Console.Out); FileStream file = new FileStream("new.xsd", FileMode.Create, FileAccess.ReadWrite); XmlTextWriter xwriter = new XmlTextWriter(file, new UTF8Encoding()); xwriter.Formatting = Formatting.Indented; myschema.Write(xwriter); } catch (Exception e) { Console.WriteLine(e); } }
public void loadWSDL(string wsdlString) { if (!wsdlString.Equals("")) { StringReader sr = new StringReader(wsdlString); XmlTextReader tx = new XmlTextReader(sr); ServiceDescription t = ServiceDescription.Read(tx); // Initialize a service description importer. ServiceDescription serviceDescription = t.Services[0].ServiceDescription; Types types = serviceDescription.Types; PortTypeCollection portTypes = serviceDescription.PortTypes; MessageCollection messages = serviceDescription.Messages; XmlSchema schema = types.Schemas[0]; PortType porttype = portTypes[0]; Operation operation = porttype.Operations[0]; OperationInput input = operation.Messages[0].Operation.Messages.Input; Message message = messages[input.Message.Name]; MessagePart messagePart = message.Parts[0]; // XmlSchemaObject fsdf = types.Schemas[0].Elements[messagePart.Element]; XmlSchema fsdf = types.Schemas[0]; if (fsdf == null) { Console.WriteLine("Test"); } StringWriter twriter = new StringWriter(); // TextWriter writer= new TextWriter(twriter); fsdf.Write(twriter); DataSet set = new DataSet(); StringReader sreader = new StringReader(twriter.ToString()); XmlTextReader xmlreader = new XmlTextReader(sreader); set.ReadXmlSchema(xmlreader); soap = new XmlDocument(); XmlNode node, envelope, header, body, securityHeader; node = soap.CreateXmlDeclaration("1.0", "ISO-8859-1", "yes"); soap.AppendChild(node); envelope = soap.CreateElement("s", "Envelope", "http://www.w3.org/2003/05/soap-envelope"); soap.AppendChild(envelope); body = soap.CreateElement("s", "Body", "http://www.w3.org/2003/05/soap-envelope"); XmlNode eingabe = soap.CreateElement("tns", set.Tables[0].ToString(), set.Tables[0].Namespace); DataTable table = set.Tables[0]; foreach (DataColumn tempColumn in table.Columns) { XmlNode neu = soap.CreateElement("tns", tempColumn.ColumnName, set.Tables[0].Namespace); eingabe.AppendChild(neu); } body.AppendChild(eingabe); envelope.AppendChild(body); mySettings.Soap = xmlToString(soap); } }
private static XmlSchema DeepCopy(XmlSchema sourceSchema) { using (var stream = new MemoryStream()) { sourceSchema.Write(stream); stream.Position = 0; return(XmlSchema.Read(stream, null)); } }
void GetSchema(TextWriter w) { XmlSchema xs = GetSchema(GetType()); if (xs != null) { xs.Write(w); } }
private static string GetXmlSchemaString(XmlSchema xmlSchema, XmlNamespaceManager? namespaceManager = null) { var encoding = new UTF8Encoding(); var memoryStream = new MemoryStream(); var settings = new XmlWriterSettings { Indent = true, NewLineChars = "\n", Encoding = encoding }; using var xmlWriter = XmlWriter.Create(memoryStream, settings); xmlSchema.Write(xmlWriter, namespaceManager); return encoding.GetString(memoryStream.ToArray()); }
public static void ЗаписатьXSDСхемуВФайл(XmlSchema схема, string имяФайлаДляСохраненияXSDСхемы) { using (XmlTextWriter writer = new XmlTextWriter(имяФайлаДляСохраненияXSDСхемы, Кодировка)) { writer.Indentation = 2; // отступ - 2 пробела writer.IndentChar = ' '; writer.Formatting = Formatting.Indented; схема.Write(writer); } }
void GenerateXmlSchema(String[] formats, String fileFormatType) { StreamWriter writer = File.CreateText(xmlSchemaFile + "_" + fileFormatType + ".xml"); XmlSchema schema; XmlSchemaElement element; XmlSchemaComplexType complexType; XmlSchemaSequence sequence; schema = new XmlSchema(); element = new XmlSchemaElement(); schema.Items.Add(element); element.Name = "Table"; complexType = new XmlSchemaComplexType(); element.SchemaType = complexType; sequence = new XmlSchemaSequence(); complexType.Particle = sequence; element = new XmlSchemaElement(); element.Name = "Number"; element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(element); for(int i=0; i<formats.Length; i++){ element = new XmlSchemaElement(); element.Name = formats[i]; element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(element); } schema.Compile(new ValidationEventHandler(ValidationCallbackOne)); schema.Write(writer); writer.Close(); }
private void WriteXMLForCultures(CultureInfo[] cultures) { StreamWriter writer = File.CreateText("CultureSchema.xml"); XmlSchema schema; XmlSchemaElement element; XmlSchemaComplexType complexType; XmlSchemaSequence sequence; schema = new XmlSchema(); element = new XmlSchemaElement(); schema.Items.Add(element); element.Name = "Table"; complexType = new XmlSchemaComplexType(); element.SchemaType = complexType; sequence = new XmlSchemaSequence(); complexType.Particle = sequence; element = new XmlSchemaElement(); element.Name = "CultureName"; element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); sequence.Items.Add(element); schema.Compile(new ValidationEventHandler(ValidationCallbackOne)); schema.Write(writer); writer.Close(); writer = File.CreateText("CultureData.xml"); XmlTextWriter myXmlTextWriter = new XmlTextWriter(writer); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); for(int j=0; j<cultures.Length; j++) { myXmlTextWriter.WriteStartElement("Table"); myXmlTextWriter.WriteElementString("CultureName", cultures[j].LCID.ToString()); myXmlTextWriter.WriteEndElement(); } myXmlTextWriter.WriteEndElement(); myXmlTextWriter.Flush(); myXmlTextWriter.Close(); }