Appends a new element containing a text value to the given target element.
/*
* RegExpress
*
* Copyright (c) 2010, Daniel McGaughran
*
* Licensed under the Apache Licence, Version 2.0 (the "Licence");
* you may not use this file except in compliance with the Licence.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*
*/
using System;
using System.Xml;
namespace RegExpressModel.Utility
{
static class XmlUtility
{
/// <summary>
/// Appends a new element containing a text value to the given target element.
/// </summary>
/// <param name="targetElement">The target element to append the text-wrapping element to.</param>
/// <param name="targetDocument">The target document.</param>
/// <param name="elementName">Name of the element to create.</param>
/// <param name="innerValue">The inner text value.</param>
/// <returns>The created element.</returns>
internal static XmlElement AppendElement(this XmlElement targetElement, XmlDocument targetDocument,
string elementName, string innerValue)
{
if (targetElement == null || targetDocument == null || String.IsNullOrEmpty(elementName))
return null;
XmlElement element = targetDocument.CreateElement(elementName);
XmlText textNode = targetDocument.CreateTextNode(innerValue);
element.AppendChild(textNode);
targetElement.AppendChild(element);
return element;
}
}
}
Related examples in the same category