(my other elements will go here as below)
My problem is getting the element to output as above, below is an example of an xml output of mine that is working fine, i just need to add the element as above?
(my above sample here)
XElement xml = new XElement("Persons", new XElement("Person",
new XElement("Server", Server.Text),
new XElement("User", Username.Text),
new XElement("Password", Password.Text),
new XElement("Recipient1", Recipient.Text),
new XElement("Recipient2", Recipient2.Text),
new XElement("Recipient3", Recipient3.Text),
new XElement("Subject", Subject.Text),
new XElement("Message", Message.Text),
new XElement("Ping", Ping.Text)));
(and ends here)
xml.Save("c:\\XMLFile.xml");
VulpesPosted Feb 16, 2012, 8:01 AM
XElement rpc = new XElement("rpc",
new XAttribute("module", "SMS"),
new XAttribute("method", "Send_SMS"),
new XAttribute("version", "1.0"));
rpc.Add(xml); // xml is your existing XElement
rpc.Save("c:\\XMLFile.xml");
mike DelvottiPosted Feb 16, 2012, 10:43 AM
VulpesPosted Feb 16, 2012, 10:36 AM
Otherwise it should work fine.
mike DelvottiPosted Feb 16, 2012, 8:42 AM
System.Xml.XmlAttribute' does not contain a constructor that takes '2' arguments
I have no doubt that I have placed it wrong somewhere though, have i done it correct as below:
XElement rpc = new XElement("rpc",
new XmlAttribute("module", "SMS"),
new XmlAttribute("method", "Send_SMS"),
new XmlAttribute("version", "1.0"));
XElement xml = new XElement("Persons", new XElement("Person",
new XElement("Server", Server.Text),
new XElement("User", Username.Text),
new XElement("Password", Password.Text),
new XElement("Recipient1", Recipient.Text),
new XElement("Recipient2", Recipient2.Text),
new XElement("Recipient3", Recipient3.Text),
new XElement("Subject", Subject.Text),
new XElement("Message", Message.Text),
new XElement("Ping", Ping.Text)));
rpc.Add(xml);
rpc.Save("c:\\XMLFile.xml");
Mahesh ChandPosted Feb 16, 2012, 7:24 AM
You can also create direct XML using XmlDocument.LoadXml as you can see below. You can also create an XmlAttribute using XmlDocument.CreateAttribute (see below).