示例#1
0
        public void CreateOutputFile(XmlDocument xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("XmlDocument cannot be null");
            }
            XmlDeclaration xmlDeclaration = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
            XmlElement     root           = xml.DocumentElement;

            xml.InsertBefore(xmlDeclaration, root);
            XmlElement policyElement = xml.CreateElement(string.Empty, "policy", string.Empty);

            foreach (var policy in myPolicies)
            {
                xml.AppendChild(policyElement);

                XmlElement policyNumberElement = xml.CreateElement(string.Empty, "policynumber", string.Empty);
                XmlText    policyNumberText    = xml.CreateTextNode(policy.PolicyNumber);
                policyNumberElement.AppendChild(policyNumberText);
                policyElement.AppendChild(policyNumberElement);

                XmlElement maturityValue = xml.CreateElement(string.Empty, "maturityvalue", string.Empty);
                XmlText    valueText     = xml.CreateTextNode(myPolicyHelper.MaturityValue(policy).PolicyValue);
                maturityValue.AppendChild(valueText);
                policyElement.AppendChild(maturityValue);
            }

            xml.Save(@"E:\MaturedPolices.xml");
        }