关于xmlschema帮助的问题 [英] question about xmlschema help
本文介绍了关于xmlschema帮助的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在msdn。
中找到了一个示例来创建xmlschema:
using System;
使用 System.Xml;
使用 System.Xml.Schema;
class XMLSchemaExamples
{
public static void Main()
{
XmlSchema schema = new XmlSchema();
//< xs:element name =" cat" type =" xs:string" />
XmlSchemaElement elementCat = new XmlSchemaElement();
schema.Items.Add(elementCat);
elementCat.Name = " cat" ;
elementCat.SchemaTypeName = new XmlQualifiedName(" string" ," HTTP://www.w3.org/2001/XMLSchema" 跨度>);
//< xs:element name =" dog" type =" xs:string" />
XmlSchemaElement elementDog = new XmlSchemaElement();
schema.Items.Add(elementDog);
elementDog.Name = " dog" ;
elementDog.SchemaTypeName = new XmlQualifiedName(" string" ," HTTP://www.w3.org/2001/XMLSchema" 跨度>);
//< xs:element name =" redDog" substitutionGroup = QUOT;狗" />
XmlSchemaElement elementRedDog = new XmlSchemaElement();
schema.Items.Add(elementRedDog);
elementRedDog.Name = " redDog" ;
elementRedDog.SubstitutionGroup = new XmlQualifiedName(" dog" );
//< xs:element name =" brownDog" substitutionGroup =" dog" />
XmlSchemaElement elementBrownDog = new XmlSchemaElement();
schema.Items.Add(elementBrownDog);
elementBrownDog.Name = " brownDog" ;
elementBrownDog.SubstitutionGroup = new XmlQualifiedName(" dog" );
//< xs:element name =" pets">
XmlSchemaElement elementPets = new XmlSchemaElement();
schema.Items.Add(elementPets);
elementPets.Name = " pets" ;
//< xs:complexType>
XmlSchemaComplexType complexType = new XmlSchemaComplexType();
elementPets.SchemaType = complexType;
//< xs:choice minOccurs =" 0" maxOccurs =" unbounded">
XmlSchemaChoice choice = new XmlSchemaChoice();
complexType.Particle = choice;
choice.MinOccurs = 0;
choice.MaxOccursString = " unbounded" ;
//< xs:element ref =" cat" />
XmlSchemaElement catRef = new XmlSchemaElement();
choice.Items.Add(catRef);
catRef.RefName = new XmlQualifiedName(" cat" );
//< xs:element ref =" dog" />
XmlSchemaElement dogRef = new XmlSchemaElement();
choice.Items.Add(dogRef);
dogRef.RefName = new XmlQualifiedName(" dog" );
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 ValidationCallbackOne( object sender,ValidationEventArgs args)
{
Console.WriteLine(args.Message);
}
}
我想获取xmlschema innertext。
我如何将innertext放入文本框?
thx
解决方案
< blockquote>
写入StringWriter而不是写入Console.Out,然后调用ToString()并分配给TextBox的Text属性:
using(StringWriter sw = new StringWriter())
{
compiledSchema.Write(sw ,nsmgr);
Textbox1.Text = sw.ToString();
}
I found a example from msdn.
to wirte a xmlschema:
using System; using System.Xml; using System.Xml.Schema; class XMLSchemaExamples { public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:element name="cat" type="xs:string"/> XmlSchemaElement elementCat = new XmlSchemaElement(); schema.Items.Add(elementCat); elementCat.Name = "cat"; elementCat.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:element name="dog" type="xs:string"/> XmlSchemaElement elementDog = new XmlSchemaElement(); schema.Items.Add(elementDog); elementDog.Name = "dog"; elementDog.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:element name="redDog" substitutionGroup="dog" /> XmlSchemaElement elementRedDog = new XmlSchemaElement(); schema.Items.Add(elementRedDog); elementRedDog.Name = "redDog"; elementRedDog.SubstitutionGroup = new XmlQualifiedName("dog"); // <xs:element name="brownDog" substitutionGroup ="dog" /> XmlSchemaElement elementBrownDog = new XmlSchemaElement(); schema.Items.Add(elementBrownDog); elementBrownDog.Name = "brownDog"; elementBrownDog.SubstitutionGroup = new XmlQualifiedName("dog"); // <xs:element name="pets"> XmlSchemaElement elementPets = new XmlSchemaElement(); schema.Items.Add(elementPets); elementPets.Name = "pets"; // <xs:complexType> XmlSchemaComplexType complexType = new XmlSchemaComplexType(); elementPets.SchemaType = complexType; // <xs:choice minOccurs="0" maxOccurs="unbounded"> XmlSchemaChoice choice = new XmlSchemaChoice(); complexType.Particle = choice; choice.MinOccurs = 0; choice.MaxOccursString = "unbounded"; // <xs:element ref="cat"/> XmlSchemaElement catRef = new XmlSchemaElement(); choice.Items.Add(catRef); catRef.RefName = new XmlQualifiedName("cat"); // <xs:element ref="dog"/> XmlSchemaElement dogRef = new XmlSchemaElement(); choice.Items.Add(dogRef); dogRef.RefName = new XmlQualifiedName("dog"); 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 ValidationCallbackOne(object sender, ValidationEventArgs args) { Console.WriteLine(args.Message); } }
i want get the xmlschema innertext.
how can i put the innertext into a Textbox?
thx
解决方案
Write to a StringWriter instead of writing to Console.Out, then call ToString() and assign to the Text property of your TextBox:
using (StringWriter sw = new StringWriter())
{
compiledSchema.Write(sw, nsmgr);
Textbox1.Text = sw.ToString();
}
这篇关于关于xmlschema帮助的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文