首页 > 代码库 > 创建XML文件
创建XML文件
//创建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文件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。