示例#1
0
        public static void SaveFormatted(AddinDescription adesc)
        {
            XmlDocument  doc       = adesc.SaveToXml();
            XmlFormatter formatter = new XmlFormatter();

            TextStylePolicy     textPolicy = new TextStylePolicy(80, 4, false, false, true, EolMarker.Unix);
            XmlFormattingPolicy xmlPolicy  = new XmlFormattingPolicy();

            XmlFormatingSettings f = new XmlFormatingSettings();

            f.ScopeXPath.Add("*/*");
            f.EmptyLinesBeforeStart = 1;
            f.EmptyLinesAfterEnd    = 1;
            xmlPolicy.Formats.Add(f);

            f = new XmlFormatingSettings();
            f.ScopeXPath.Add("Addin");
            f.AttributesInNewLine = true;
            f.AlignAttributes     = true;
            f.AttributesInNewLine = false;
            xmlPolicy.Formats.Add(f);

            string xml = formatter.FormatXml(textPolicy, xmlPolicy, doc.OuterXml);

            File.WriteAllText(adesc.FileName, xml);
        }
示例#2
0
        public static string SaveFormattedXml(PolicyContainer policies, AddinDescription adesc)
        {
            XmlDocument doc = adesc.SaveToXml();

            TextStylePolicy     textPolicy = policies.Get <TextStylePolicy> (DesktopService.GetMimeTypeInheritanceChain("application/x-addin+xml"));
            XmlFormattingPolicy xmlPolicy  = policies.Get <XmlFormattingPolicy> (DesktopService.GetMimeTypeInheritanceChain("application/x-addin+xml"));

            return(XmlFormatter.FormatXml(textPolicy, xmlPolicy, doc.OuterXml));
        }
示例#3
0
        public void OmitXmlDeclarationIsFalse_XmlDeclarationExists_XmlDeclarationUnmodified()
        {
            xmlPolicy.DefaultFormat.OmitXmlDeclaration = false;
            string input          = "<?xml version=\"1.0\"?><a></a>";
            string expectedResult = "<?xml version=\"1.0\"?>\n<a>\n</a>";

            string result = XmlFormatter.FormatXml(textPolicy, xmlPolicy, input);

            Assert.AreEqual(expectedResult, result);
        }
示例#4
0
        public void OmitXmlDeclarationIsTrue_XmlDeclarationExists_XmlDeclarationRemoved()
        {
            xmlPolicy.DefaultFormat.OmitXmlDeclaration = true;
            string input          = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a></a>";
            string expectedResult = "<a>\n</a>";

            string result = XmlFormatter.FormatXml(textPolicy, xmlPolicy, input);

            Assert.AreEqual(expectedResult, result);
        }
示例#5
0
        public void OmitXmlDeclarationIsFalse_XmlDeclarationDoesNotExist_XmlDeclarationIsAdded()
        {
            xmlPolicy.DefaultFormat.OmitXmlDeclaration = false;
            string input          = "<a></a>";
            string expectedResult = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<a>\n</a>";

            string result = XmlFormatter.FormatXml(textPolicy, xmlPolicy, input);

            Assert.AreEqual(expectedResult, result);
        }
示例#6
0
        public void AlignAttributesMaxOnePerLine()
        {
            var myTextPolicy = textPolicy.WithTabsToSpaces(true);
            var myXmlPolicy  = xmlPolicy.Clone();

            myXmlPolicy.DefaultFormat.AlignAttributes      = true;
            myXmlPolicy.DefaultFormat.MaxAttributesPerLine = 1;
            myXmlPolicy.DefaultFormat.OmitXmlDeclaration   = true;
            string input = @"<test123 abc=""x"" def=""y"" ghi=""z"" />";
            //9 spaces = "<test123 ".Length
            string expectedResult = "<test123 abc=\"x\"\n         def=\"y\"\n         ghi=\"z\" />";

            string result = XmlFormatter.FormatXml(myTextPolicy, myXmlPolicy, input);

            Assert.AreEqual(expectedResult, result);
        }