码迷,mamicode.com
首页 > 其他好文 > 详细

创建XML文件

时间:2014-08-29 23:55:38      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:des   style   os   io   ar   for   文件   2014   div   

//创建XML文件
             XmlDocument xmldoc = new XmlDocument();
            XmlText xmltext;
             XmlNode xmlnode = xmldoc.CreateXmlDeclaration( "1.0", "utf-8" , null );
             xmldoc.AppendChild(xmlnode);
           
             XmlElement xmlcast = xmldoc.CreateElement( "", "Cast","" );
              xmltext = xmldoc.CreateTextNode( "");
             xmlcast.AppendChild(xmltext);
             xmldoc.AppendChild(xmlcast);

             XmlElement xmlsend = xmldoc.CreateElement( "", "SendUserId", "" );
             xmltext = xmldoc.CreateTextNode( WangCaiConfig.User.Id.ToString());
             xmlsend.AppendChild(xmltext);
             xmldoc.ChildNodes.Item(1).AppendChild(xmlsend);

             XmlElement xmlmessage = xmldoc.CreateElement( "", "Message", "" );
             xmltext = xmldoc.CreateTextNode(content);
             xmlmessage.AppendChild(xmltext);
             xmldoc.ChildNodes.Item(1).AppendChild(xmlmessage);

             XmlElement xmlsubect = xmldoc.CreateElement( "", "Subject", "" );
             xmltext = xmldoc.CreateTextNode(title);
             xmlsubect.AppendChild(xmltext);
             xmldoc.ChildNodes.Item(1).AppendChild(xmlsubect);

             XmlElement xmlstate = xmldoc.CreateElement( "", "State", "" );
             xmltext = xmldoc.CreateTextNode( "1");
             xmlstate.AppendChild(xmltext);
             xmldoc.ChildNodes.Item(1).AppendChild(xmlstate);

             XmlElement xmltime = xmldoc.CreateElement( "", "SendTime", "" );
             xmltext = xmldoc.CreateTextNode(time.ToString());
             xmltime.AppendChild(xmltext);
             xmldoc.ChildNodes.Item(1).AppendChild(xmltime);

             XmlElement xmlUserList = xmldoc.CreateElement( "", "UserList", "" );
             xmltext = xmldoc.CreateTextNode( "");
             xmlUserList.AppendChild(xmltext);
             xmldoc.ChildNodes.Item(1).AppendChild(xmlUserList);

             string[] str = acceptUserId.Split( new char[] { ‘&‘ });
             for ( int i = 0; i < str.Length; i++)
             {
                 XmlElement xmlaccept = xmldoc.CreateElement( "", "UserId", "" );
                 xmltext = xmldoc.CreateTextNode(str[i].ToString());
                 xmlaccept.AppendChild(xmltext);
                 xmldoc.ChildNodes.Item(1).AppendChild(xmlUserList).AppendChild(xmlaccept);
             }
            xmldoc.Save( WangCaiConfig.GetCurrentDirectory()+"UserXML/BoradCast.xml" );

创建出来的样式
<?xml version="1.0" encoding =" utf-8" ?>
<Cast>
  <SendUserId> 3</ SendUserId>
  <Message> sasdasd</ Message>
  <Subject> 3244</ Subject>
  <State> 1</ State>
  <SendTime> 2014/8/29 14:23:50</SendTime >
  <UserList>
    <UserId> 42</ UserId>
    <UserId> 43</ UserId>
  </UserList>
</Cast>

创建XML文件

标签:des   style   os   io   ar   for   文件   2014   div   

原文地址:http://www.cnblogs.com/xiaoyaodijun/p/3945882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!