xml的问题
提交一个XML,但提示说XML没根元素。郁闷。大家看看
XmlDocument fsxml = new XmlDocument();
XmlDeclaration fssmxml;
fssmxml=fsxml.CreateXmlDeclaration( "1.0 ", "gb2312 ", "yes ");
fsxml.AppendChild(fssmxml);
XmlElement sxrmxx =fsxml.CreateElement( "SXRMXX ");
XmlNode s =fsxml.SelectSingleNode( "SXRMXX ");
XmlElement login =fsxml.CreateElement( "LOGIN ");
XmlElement username =fsxml.CreateElement( "USERNAME ");
username.InnerText= "103005 ";
login.AppendChild(username);
XmlElement password = fsxml.CreateElement( "PASSWORD ");
password.InnerText = "103005 ";
login.AppendChild(password);
sxrmxx.AppendChild(login);
//XmlNode sxrmxx2 =fsxml.SelectSingleNode( "SXRMXX ");
XmlElement operation =fsxml.CreateElement( "OPERATION ");
operation.InnerText= "1 ";
sxrmxx.AppendChild(operation);
XmlElement unitinfo =fsxml.CreateElement( "UNITINFO ");
XmlElement xzqh = fsxml.CreateElement( "XZQH ");
xzqh.InnerText= "103005 ";
unitinfo.AppendChild(xzqh);
XmlElement dwbm = fsxml.CreateElement( "DWBM ");
dwbm.InnerText= "440100 ";
unitinfo.AppendChild(dwbm);
sxrmxx.AppendChild(unitinfo);//添加unitinfo
fsxml.Save(Server.MapPath(strFileName));
[解决办法]
最后加上 fsxml.AppendChild(sxrmxx);