using System.Xml;

namespace QTMDataFormat;

public class XMLHandler
{
	public static XmlElement CreateElement(XmlDocument xmlDoc, string ElementName, string Text)
	{
		XmlElement xmlElement = xmlDoc.CreateElement("", ElementName, "");
		XmlText newChild = xmlDoc.CreateTextNode(Text.Trim());
		xmlElement.AppendChild(newChild);
		return xmlElement;
	}

	public static string GetTagValue(XmlDocument xmlRoot, string TagName)
	{
		try
		{
			return xmlRoot.GetElementsByTagName(TagName)[0].InnerText;
		}
		catch
		{
		}
		return "";
	}

	public static string GetNodeValue(XmlDocument xmlDoc, string tagName)
	{
		string result = "";
		if (xmlDoc != null && tagName != null && tagName.Trim() != "")
		{
			XmlNode xmlNode = xmlDoc.SelectSingleNode("Root/" + tagName);
			result = xmlNode.InnerText;
		}
		return result;
	}
}
