public void AddPI(object doc, string data)
        {
            XmlDocument xmlDocument = InMetaXmlUtils.TryGetXmlDocument(doc);

            if (xmlDocument != null)
            {
                XmlNode firstChild = xmlDocument.FirstChild;
                if (firstChild != null && (firstChild.NodeType == XmlNodeType.ProcessingInstruction && firstChild.Name == "xml"))
                {
                    xmlDocument.RemoveChild(firstChild);
                }
                XmlProcessingInstruction processingInstruction = xmlDocument.CreateProcessingInstruction("xml", data);
                xmlDocument.InsertBefore((XmlNode)processingInstruction, xmlDocument.FirstChild);
            }
            else
            {
                object firstChild = InMetaXmlUtils.InteropGetFirstChild(doc);
                if (firstChild != null && (InMetaXmlUtils.InteropGetNodeType(firstChild) == 7 && InMetaXmlUtils.InteropGetNodeName(firstChild) == "xml"))
                {
                    InMetaXmlUtils.InteropRemoveChild(doc, firstChild);
                }
                object processingInstruction = InMetaXmlUtils.InteropCreateProcessingInstruction(doc, "xml", data);
                InMetaXmlUtils.InteropInsertBefore(doc, processingInstruction, InMetaXmlUtils.InteropGetFirstChild(doc));
            }
        }
        public void SetNodeText(object element, string text, bool textAsCDataSection = false)
        {
            XmlNode xmlNode = InMetaXmlUtils.TryGetXmlNode(element);

            if (xmlNode != null)
            {
                XmlUtils.ReplaceOwnText(xmlNode, text);
            }
            else
            {
                object nodes  = InMetaXmlUtils.InteropSelectNodes(element, "text()");
                int    length = InMetaXmlUtils.InteropGetLength(nodes);
                for (int index = 0; index < length; ++index)
                {
                    InMetaXmlUtils.InteropRemoveChild(element, InMetaXmlUtils.InteropGetItem(nodes, index));
                }
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }
                InMetaXmlUtils.InteropAppendChild(element, InMetaXmlUtils.InteropCreateTextNode(InMetaXmlUtils.InteropGetOwnerDocument(element), text));
            }
        }