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 '
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="
</Cities>
很明显,属性和元素的区别。
State="Italy"是属性定义,Rome属于元素定义也就是节点。
浙公网安备 33010602011771号