SharePoint Tips

Thursday, November 16, 2017

C# - Create Static XML Node

public static void CreateStaticXmlNode(XmlDocument xmlDoc, XmlNode parentNode)
{
//Node 1
XmlNode childNodeOne = xmlDoc.CreateElement("MFITEM");
XmlAttribute attMFTYPE = xmlDoc.CreateAttribute("TYPE");
attMFTYPE.InnerText = "FILE";
childNodeOne.Attributes.Append(attMFTYPE);
XmlAttribute attMFKEY = xmlDoc.CreateAttribute("KEY");
attMFKEY.InnerText = "FileName.pdf";
childNodeOne.Attributes.Append(attMFKEY);
XmlNode nodeMFTitle = xmlDoc.CreateElement("TITLE");
nodeMFTitle.InnerText = "<![CDATA[Test Form]]>";
childNodeOne.AppendChild(nodeMFTitle);
parentNode.AppendChild(childNodeOne);
//Node 2
XmlNode childNodeTwo = xmlDoc.CreateElement("MFITEM");
XmlAttribute attIncSheetType = xmlDoc.CreateAttribute("TYPE");
attIncSheetType.InnerText = "FILE";
childNodeTwo.Attributes.Append(attIncSheetType);
XmlAttribute attSK = xmlDoc.CreateAttribute("KEY");
attSK.InnerText = "FileName.pdf";
childNodeTwo.Attributes.Append(attSK);
XmlNode childNodeTwoTitle = xmlDoc.CreateElement("TITLE");
childNodeTwoTitle.InnerText = "<![CDATA[Test Text]]>";
childNodeTwo.AppendChild(childNodeTwoTitle);
parentNode.AppendChild(childNodeTwo);
}

No comments:

Post a Comment