I have an XML:
<PolicyChangeSet schemaVersion="2.1" username="" description="">
<Note>
<Content></Content>
</Note>
<Attachments>
<Attachment name="" contentType="">
<Description></Description>
<Location></Location>
</Attachment>
</Attachments>
</PolicyChangeSet>
I have a method that populates the XML:
public static void GeneratePayLoad(string url, string policyID)
{
string attachmentName = policyID.Split(new string[] { "REINSTMT" }, StringSplitOptions.None)[0] + "REINSTMT";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(AppVars.pxCentralXMLPayloadFilePath);
XmlNode node = xmlDoc.SelectSingleNode("/PolicyChangeSet");
node.Attributes["username"].Value = AppVars.Username;
node.Attributes["description"].Value = "Upload Documents";
node = xmlDoc.SelectSingleNode("PolicyChangeSet/Note/Content");
node.InnerText = "The attached pictures were sent by the producer.";
node = xmlDoc.SelectSingleNode("/PolicyChangeSet/Attachments/Attachment");
node.Attributes["name"].Value = attachmentName;
node.Attributes["contentType"].Value = "image/tiff";
node = xmlDoc.SelectSingleNode("/PolicyChangeSet/Attachments/Attachment/Description");
node.InnerText = "Combined reinstatement picture file";
node = xmlDoc.SelectSingleNode("/PolicyChangeSet/Attachments/Attachment/Location");
node.InnerText = url;
xmlDoc.Save(AppVars.pxCentralXMLPayloadFilePath);
}
My question is, what is the optimal way to populate the XML? I feel like there is an easier way to do it. For example, I'm sure there's a way to eliminate the need to select a single node multiple times (something I'm currently doing). What do you guys recommend? What is the best way?