问题描述
<graphcaption='MonthlyUnitSales'xAxisName='Month'yAxisName='Units'decimalPrecision='0'formatNumberScale='0'><setname='Jan'value='462'color='AFD8F8'/><setname='Feb'value='857'color='F6BD0F'/><setname='Mar'value='671'color='8BBA00'/><setname='Apr'value='494'color='FF8E46'/><setname='May'value='761'color='008E8E'/><setname='Jun'value='960'color='D64646'/><setname='Jul'value='629'color='8E468E'/><setname='Aug'value='622'color='588526'/><setname='Sep'value='376'color='B3AA00'/><setname='Oct'value='494'color='008ED6'/><setname='Nov'value='761'color='9D080D'/><setname='Dec'value='960'color='A186BE'/></graph>我想写一个这样格式的XML文件出来.怎么写啊..大家帮帮我啊
解决方案
解决方案二:
//xmlpath=@"F:AjaxControlToolkitWebSite1order"+xmlname+".xml";Session["url"]=xmlpath;//FileStreamstream=newFileStream(xmlpath);File.Delete(xmlpath);stream=File.OpenWrite(xmlpath);//表示提供快速、非缓存、只进方法的编写器,该方法生成包含XML数据//(这些数据符合W3C可扩展标记语言(XML)1.0和XML中命名空间的建议)的流或文件XmlTextWriterwriter=newXmlTextWriter(stream,System.Text.Encoding.UTF8);////指定XmlTextWriter的格式设置选项writer.Formatting=Formatting.Indented;////写出在名称和文本之间带有空格的处理指令writer.WriteProcessingInstruction("xml","version="1.0"encoding="utf-8"");writer.WriteStartElement("","Products","");writer.WriteString("");writer.WriteEndElement();writer.Close();------------------stringpath=Session["url"].ToString();xmlDoc.Load(path);XmlNoderoot=xmlDoc.SelectSingleNode("Products");XmlElementxe1=xmlDoc.CreateElement("Product");//创建一个<Product>节点xe1.SetAttribute("id",id);//设置该节点id属性xe1.SetAttribute("Name",name);//设置该节点Name属性xe1.SetAttribute("Price",price);//设置该节点Price属性xe1.SetAttribute("image",imageurl);//设置个时间id区分每个idstringtime_id=System.DateTime.Now.ToString("yyyy-MM-ddhh-mm-ss");xe1.SetAttribute("time_id",time_id);root.AppendChild(xe1);//添加到<bookstore>节点中xmlDoc.Save(path);
解决方案三:
XmlDocumentxmlDoc=newXmlDocument();XmlNodexmlnod=xmlDoc.CreateNode(XmlNodeType.XmlDeclaration,"","");xmlDoc.AppendChild(xmlnod);XmlElementxmlelem=xmlDoc.CreateElement("graph");XmlAttributeattr1=newXmlAttribute();attr1.Name="caption";attr1.Value="MonthlyUnitSales";xmlelem.Attributes.Append(attr1);XmlElementsetElem=xmlDoc.CreateElement("set");xmlelem.AppendChild(setElem);xmlDoc.Save("c:aaa.xml");
以上没写全,剩下的楼主就靠你自己理解了啊。基本上就这些操作了。
解决方案四:
//创建一个XmlDocument对象XmlDocumentdoc=newXmlDocument();doc.LoadXml("<graphcaption='MonthlyUnitSales'xAxisName='Month'yAxisName='Units'decimalPrecision='0'formatNumberScale='0'>"+"<setname='Jan'value='462'color='AFD8F8'/>"+"<setname='Feb'value='857'color='F6BD0F'/>"+"<setname='Mar'value='671'color='8BBA00'/>"+"<setname='Apr'value='494'color='FF8E46'/>"+"<setname='May'value='761'color='008E8E'/>"+"<setname='Jun'value='960'color='D64646'/>"+"<setname='Jul'value='629'color='8E468E'/>"+"<setname='Aug'value='622'color='588526'/>"+"<setname='Sep'value='376'color='B3AA00'/>"+"<setname='Oct'value='494'color='008ED6'/>"+"<setname='Nov'value='761'color='9D080D'/>"+"<setname='Dec'value='960'color='A186BE'/>"+"</graph>");//保存这个文档到文件中doc.Save("c:\data.xml");
解决方案五:
//创建一个XmlDocument对象XmlDocumentdoc=newXmlDocument();doc.LoadXml("<graphcaption='MonthlyUnitSales'xAxisName='Month'yAxisName='Units'decimalPrecision='0'formatNumberScale='0'>"+"<setname='Jan'value='462'color='AFD8F8'/>"+"<setname='Feb'value='857'color='F6BD0F'/>"+"<setname='Mar'value='671'color='8BBA00'/>"+"<setname='Apr'value='494'color='FF8E46'/>"+"<setname='May'value='761'color='008E8E'/>"+"<setname='Jun'value='960'color='D64646'/>"+"<setname='Jul'value='629'color='8E468E'/>"+"<setname='Aug'value='622'color='588526'/>"+"<setname='Sep'value='376'color='B3AA00'/>"+"<setname='Oct'value='494'color='008ED6'/>"+"<setname='Nov'value='761'color='9D080D'/>"+"<setname='Dec'value='960'color='A186BE'/>"+"</graph>");//保存这个文档到文件中doc.Save("c:\data.xml");
解决方案六:
mark
解决方案七:
mark