大侠:
我想要的格式是:
<content width="1397" height="2056" bgcolor="cccccc" loadercolor="ffffff" panelcolor="5d5d61" buttoncolor="5d5d61" textcolor="ffffff">
<page src="pages/1.jpg"/>
</content>
代码为:
using (XmlWriter writer = XmlWriter.Create("C://my.xml"))
{
writer.WriteStartDocument(false);
writer.WriteStartElement("content");
//writer.WriteAttributeString("xmlns", "emp", null, "urn:employees-wrox");
writer.WriteStartElement("page");
///xml标签一开始
writer.WriteAttributeString("src", "pages/1.jpg");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
lblResult.Visible = true;
lblResult.Text = "File is written successfully";
}
哪位大侠可以告诉我 那个 content 标签里面的格式是怎么生成的吗?请附有代码,在线等~~~
------解决方案--------------------
直接用XmlDocument操作
XmlDocument doc = new XmlDocument();
XmlElement content = doc.CreateElement("content");
XmlAttribute width = doc.CreateAttribute("width");
width.Value = "1397";
content.Attributes.Append(width);
XmlAttribute height = doc.CreateAttribute("height");
width.Value = "2056";
content.Attributes.Append(height);
......
XmlElement page = doc.CreateElement("page");
content.AppendChild(page);
doc.AppendChild(content);
doc.Save("D:\\123.xml");
------解决方案--------------------
楼上+1
------解决方案--------------------
在DataContract
[DataContract]
[XmlRoot(Namespace = "", ElementName = "content")]
和DataMember
[DataMember(Name = "width", Order = 1)]
[XmlAttribute(AttributeName = "width")]
调用web service指定XML格式就是你要的格式,不需要另外写代码。它自己会序列化成你要的。