Пример #1
0
        /// <summary>
        /// Used to make sure that the input for the guide body parses correctly as valid XML
        /// </summary>
        /// <returns>A string that represents the XML for the guide body</returns>
        private string TryParseGuideBody()
        {
            XmlDocument bodyDoc = new XmlDocument();
            XmlNode guideBody = null;
            try
            {
                // Load the body text into an XmlDoc to parse
                bodyDoc.LoadXml(Entities.GetEntities() + "<GUIDE><BODY>" + _template.UIFields["Body"].RawValue + "</BODY></GUIDE>");
                guideBody = bodyDoc.SelectSingleNode("//GUIDE");
            }
            catch (XmlException ex)
            {
                AddErrorXml("GuideXML", "The body text contains invalid XML - " + ex.Message, _typedArticleNode);
                return "";
            }

            // Create the extra info block
            int type = _template.UIFields["Type"].ValueInt;
            ExtraInfo extraInfo = new ExtraInfo();
            extraInfo.TryCreate(type, "");

            // Now add all the non required fields to the Guide
            Dictionary<string, UIField>.Enumerator validFields = _template.UIFields.GetEnumerator();
            while (validFields.MoveNext())
            {
                // Check to see if we've got a non require field
                UIField currentField = validFields.Current.Value;
                if (!currentField.Required)
                {
                    // Add the field to the extra info
                    extraInfo.AddExtraInfoTagValue(currentField.Name, currentField.ValueString);

                    // Add the element to the 
                    XmlDocument fieldDoc = new XmlDocument();
                    try
                    {
                        // Load the text into an XmlDoc to parse
                        fieldDoc.LoadXml("<" + currentField.Name.ToUpper() + ">" + currentField.RawValue + "</" + currentField.Name.ToUpper() + ">");
                        XmlNode bodyNode = bodyDoc.SelectSingleNode("//BODY");
                        XmlNode importNode = bodyDoc.ImportNode(fieldDoc.FirstChild,true);
                        bodyDoc.DocumentElement.InsertAfter(importNode, bodyNode);
                    }
                    catch (XmlException ex)
                    {
                        AddErrorXml("GuideXML", "The " + currentField.Name + " contains invalid XML - " + ex.Message, _typedArticleNode);
                        return "";
                    }
                }
            }

            // Add the guidebody to the page
            _typedArticleNode.AppendChild(_typedArticleNode.OwnerDocument.ImportNode(guideBody,true));
            AddInside(_typedArticleNode, extraInfo);

            // Get the text to insert into the database
            return guideBody.OuterXml.ToString();
        }