コード例 #1
0
 /// <summary> XMLCursor from a Xambler. </summary>
 /// <param name="xambler"> Xambler to make Xml from </param>
 public XMLSlice(Xambler xambler) : this(
         new TextOf(
             new ScalarOf <string>(() => xambler.Xml())
             )
         )
 {
 }
コード例 #2
0
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Xambler to modify xml </param>
 public XMLPatched(IScalar <XNode> xml, Xambler xambler) : this(
         new ScalarOf <IXML>(() =>
                             new XMLCursor(xambler.Apply(xml.Value()))
                             )
         )
 {
 }
コード例 #3
0
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Patching Xambler </param>
 public XMLPatched(IXML xml, Xambler xambler) : this(
         new ScalarOf <XNode>(
             () => xml.AsNode()
             ),
         xambler
         )
 {
 }
コード例 #4
0
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Patching Xambler </param>
 public XMLPatched(IScalar <string> xml, Xambler xambler) : this(
         new ScalarOf <XNode>(() =>
 {
     return(XDocument.Parse(xml.Value()));
 }
                              ),
         xambler
         )
 { }
コード例 #5
0
        public void TakesDirectiveParams()
        {
            string xml =
                new Xambler(
                    new Directives(
                        new AddDirective("page"),
                        new AddDirective("child-node")
                        )
                    ).Xml();

            Assert.NotNull(FromXPath(xml, "/page/child-node"));
        }
コード例 #6
0
        public void AddsElementsCaseSensitively()
        {
            var xml =
                new Xambler(
                    new Directives()
                    .Add("XHtml")
                    .AddIf("Body")
                    ).Xml();

            Assert.True(
                xml == "<?xml version=\"1.0\" encoding=\"utf-16\"?><XHtml><Body /></XHtml>"
                );
        }
コード例 #7
0
        public void MakesXmlDocument(string testXPath)
        {
            string xml =
                new Xambler(
                    new Directives()
                    //.pi("xml-stylesheet", "none")
                    .Add("page")
                    .Attr("the-name", "with \u20ac")
                    .Add("child-node").Set(" the text\n").Up()
                    .Add("big-text").Cdata("<<hello!!!>>").Up()
                    ).Xml();

            Assert.NotNull(FromXPath(xml, testXPath));
        }
コード例 #8
0
        public void PopThrowsException()
        {
            var dom = new XDocument();

            Assert.Throws <ImpossibleModificationException>(() =>
            {
                var innerXml = new Xambler(
                    new AddDirective("root"),
                    new AddDirective("foo"),
                    new AddDirective("bar"),
                    new PopDirective()
                    ).Apply(dom).ToString(SaveOptions.DisableFormatting);
            });
        }
コード例 #9
0
        public void CreatesXmlWithoutHeaderFromXmlQuietly()
        {
            string xml =
                new Xambler(
                    new Directives()
                    .Add("page")
                    .Add("child-node").Set(" the text\n")
                    ).XmlQuietly(false);

            Assert.StartsWith(
                "<page><child-node>",
                xml
                );
        }
コード例 #10
0
        public void CreatesXmlWithHeaderFromXmlQuietly()
        {
            string xml =
                new Xambler(
                    new Directives()
                    .Add("page")
                    .Add("child-node").Set(" the text\n")
                    ).XmlQuietly();

            Assert.StartsWith(
                "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
                xml
                );
        }
コード例 #11
0
        public void PushesAndPops()
        {
            var dom      = new XDocument();
            var innerXml = new Xambler(
                new AddDirective("root"),
                new PushDirective(),
                new AddDirective("foo"),
                new AddDirective("bar"),
                new PopDirective(),
                new SetDirective("Hello World")
                ).Apply(dom).ToString(SaveOptions.DisableFormatting);

            Assert.True(innerXml == "<root>Hello World</root>", "Push/Pop directive failed");
        }
コード例 #12
0
        public void PrependsProcessingInstructionsToDomRoot()
        {
            var dom = new Xambler(
                new Yaapii.Atoms.Enumerable.ManyOf <IDirective>(
                    new PiDirective("alpha", "beta \u20ac"),
                    new AddDirective("x4")
                    )
                ).Dom();

            Assert.Equal(
                "<?alpha beta €?><x4 />",
                dom.ToString(SaveOptions.DisableFormatting)
                );
        }
コード例 #13
0
        public void PushesAndPopsCursor(string testXPath)
        {
            var xml =
                new Xambler(
                    new Directives()
                    .Add("jeff")
                    .Push().Add("lebowski")
                    .Push().Xpath("/jeff").Add("dude").Pop()
                    .Attr("birthday", "today").Pop()
                    .Add("los-angeles")
                    ).Xml();

            Assert.True(
                null != FromXPath(xml, testXPath)
                );
        }
コード例 #14
0
 public void RejectsAddingToDocumentNode()
 {
     Assert.Throws <ImpossibleModificationException>(() =>
     {
         var xml     = new XDocument();
         var xambler =
             new Xambler(
                 new Directives()
                 .Add("root")
                 .Add("child")
                 .Xpath("/")
                 .Attr("some", "attribute")
                 ).Apply(xml);
     }
                                                     );
 }
コード例 #15
0
        public void AddsMapOfValues(string testXPath)
        {
            var dom = new XDocument(new XElement("root"));
            var xml =
                new Xambler(
                    new Directives()
                    .Xpath("//root")
                    .Add(
                        new Dictionary <String, Object>()
            {
                { "first", 1 },
                { "second", "two" }
            })
                    .Add("third")
                    ).Apply(dom).ToString(SaveOptions.DisableFormatting);

            Assert.True(FromXPath(xml, testXPath) != null);
        }
コード例 #16
0
        public void NavigatesFromRootAfterDeletedNode()
        {
            var xml     = XDocument.Load(new InputOf("<root><child name='Jerome'><property name='test'/></child></root>").Stream());
            var xambler =
                new Xambler(
                    new Directives()
                    .Xpath("/root/child[@name='Jerome']/property[@name='test']")
                    .Remove()       // Node will be deleted. After this operation the cursor points to the parent nodes.
                    .Xpath("/root/child[@name='Jerome']")
                    .Add("property")
                    .Attr("name", "test2")
                    ).Apply(xml);

            Assert.Equal(
                "<root><child name=\"Jerome\"><property name=\"test2\" /></child></root>",
                xambler.ToString(SaveOptions.DisableFormatting)
                );
        }
コード例 #17
0
        public void AddsProcessingInstructionsDirectlyToDom()
        {
            var dom = new Xambler(
                new Yaapii.Atoms.Enumerable.ManyOf <IDirective>(
                    new AddDirective("xxx")
                    )
                ).Dom();

            new PiDirective("x", "y").Exec(
                dom,
                new DomCursor(
                    new List <XNode>()
                    ),
                new DomStack()
                );

            Assert.Equal(
                "<?x y?><xxx />",
                dom.ToString(SaveOptions.DisableFormatting)
                );
        }
コード例 #18
0
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Patching Xambler </param>
 public XMLPatched(string xml, Xambler xambler) : this(
         new ScalarOf <string>(xml),
         xambler
         )
 {
 }
コード例 #19
0
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Patching Xambler </param>
 public XMLPatched(IText xml, Xambler xambler) : this(
         new ScalarOf <string>(() => xml.AsString()),
         xambler
         )
 {
 }
コード例 #20
0
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Patching Xambler </param>
 public XMLPatched(XNode xml, Xambler xambler) : this(
         new ScalarOf <XNode>(xml),
         xambler
         )
 {
 }