Ejemplo n.º 1
0
        private static XmlDeclaration _getXmlDeclaration(TransformBase t)
        {
            XmlDocument xmlDocument = XmlHelpers.CreateXmlDocument();

            xmlDocument.LoadXml(t.XmlContent);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);

            nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
            XmlNode xmlNode = xmlDocument.SelectSingleNode("//xsl:output", nsmgr);

            if (xmlNode == null || xmlNode.Attributes.GetNamedItem("omit-xml-declaration") != null && xmlNode.Attributes.GetNamedItem("omit-xml-declaration").Value == "yes")
            {
                return((XmlDeclaration)null);
            }
            string version    = xmlNode.Attributes.GetNamedItem("version") == null ? "1.0" : xmlNode.Attributes.GetNamedItem("version").Value;
            string encoding   = xmlNode.Attributes.GetNamedItem("encoding") == null ? "UTF-8" : xmlNode.Attributes.GetNamedItem("encoding").Value;
            string standalone = xmlNode.Attributes.GetNamedItem("standalone") == null ? "no" : xmlNode.Attributes.GetNamedItem("standalone").Value;

            return(xmlDocument.CreateXmlDeclaration(version, encoding, standalone));
        }