日期:2014-05-20  浏览次数:20999 次

写Xml title属性设置?????
XmlTextWriter   myWriter   =   new   XmlTextWriter( "e:\\data.xml ",System.Text.Encoding.GetEncoding( "GB2312 "));  
                myWriter.WriteStartElement( "book ");        
                myWriter.WriteElementString( "name ",   "This   is   a   book   name. ");    
                myWriter.WriteEndElement();
                myWriter.Flush();
                myWriter.Close();


<book>
<name> This   is   a   book   name. </name>
</book>

如何同时将title属性写入这个name节点????谢谢!!!

------解决方案--------------------
try..

XmlTextWriter myWriter = new XmlTextWriter(@ "../../test.xml ", System.Text.Encoding.GetEncoding( "GB2312 "));
myWriter.Formatting = Formatting.Indented;
myWriter.WriteStartElement( "book ");
myWriter.WriteStartElement( "name ");
myWriter.WriteAttributeString( "title ", "test ");
myWriter.WriteString( "This is a book name ");
myWriter.WriteEndElement();
myWriter.WriteEndElement();
myWriter.Flush();
myWriter.Close();