chiname

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

关于如何创建属性和元素,还有如何引用实体

关于如何创建属性和元素,还有如何引用实体

Posted on 2004-04-22 14:02 柚子nan 阅读(286) 评论(0)  编辑 收藏

XMLTextWrite类的一点简单的代码,

 

string fileName = @"d:\open.xml";

XmlTextWriter xmlw = new XmlTextWriter(fileName,System.Text.Encoding.Default);

xmlw.Formatting = Formatting.Indented;

 

xmlw.WriteStartDocument(true);

xmlw.WriteDocType("MyDef",null,null,"<!ENTITY I 'Italy'><!ENTITY I-Capital  'Rome'>");

 

                            xmlw.WriteStartElement("Cities");

                            xmlw.WriteStartElement("City");

                            xmlw.WriteAttributeString("Zip","201818");

 

                            xmlw.WriteStartAttribute("State",null);

                            xmlw.WriteEntityRef("I");

                            xmlw.WriteEndAttribute();

 

                            xmlw.WriteEntityRef("I-Capital");

 

                            xmlw.WriteEndElement();

                            xmlw.WriteEndElement();

 

                            xmlw.WriteEndDocument();

 

xmlw.Close();

 

输出的结果如下:

<?xml version="1.0" encoding="gb2312" standalone="yes" ?>

  <!DOCTYPE MyDef (View Source for full doctype...)>

- <Cities>

      <City Zip="201818" State="Italy">Rome</City>

  </Cities>


很明显,属性和元素的区别。
State="Italy"是属性定义,Rome属于元素定义也就是节点

posted on 2005-04-22 09:19  把我的欢乐带给你  阅读(268)  评论(0)    收藏  举报