Chinaunix首页 | 论坛 | 博客
  • 博客访问: 248968
  • 博文数量: 59
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 752
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-01 20:49
文章分类
文章存档

2011年(24)

2010年(12)

2009年(18)

2008年(5)

我的朋友

分类: C/C++

2010-07-30 15:11:01

最近用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",);

try

{

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

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

}

catch()

...

 
 
}
阅读(486) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~