首页 > Windows开发 > 详细

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

时间:2015-11-21 07:04:40      阅读:311      评论:0      收藏:0      [点我收藏+]
最近用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()

...
 
 
}

 

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

原文:http://www.cnblogs.com/joean/p/4982876.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!