Xml Schema:C#访问在complextype中插入新元素

最近用c#写Xml Schema代码,找了很久也找不到如何在已有的complextype中插入新的element,最后我充分发挥自己的聪明才智,哈哈,终于从...中找到了灵感。


XmlSchemaSet xmlSSet;
foreach( XmlSchema schema in xmlSSet.Schemas())
{
XmlSchemaElement  xmlSchRootElement = (XmlSchemaElement )schema.Items[0];//schema里面只能看到根节点元素,complextype里面的东西需要下一步提取
XmlSchemaComplexType xmlSchComlex = (XmlSchemaComplexType)xmlSchRootElement.ElementSchemaType;//这一步最关键,找到complextype的对象
XmlSchemaSequece xmlSchSeq = (XmlSchemaSequece)xmlSchComlex.Particle;//找到相应的元素
XmlSchemaElement  xmlSchNewE =new XmlSchemaElement  ();

xmlSchNewE.Name ="name";

xmlSchNewE.SchemaTypeName = new XmlQualifiedName("unsignedByte",http://www.w3.org/2001/XMLSchema);

try

{

xmlSeq.Items.Insert(0,xmlSchNewE);//0为索引,自已改

xmlSSet.Reprocess(schema);//这个是为了保障更改后xmlSSet重新识别

}

catch()

...
 
 
}
原文地址:https://www.cnblogs.com/joean/p/4982876.html