/// <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()) ) ) { }
/// <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())) ) ) { }
/// <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 ) { }
/// <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 ) { }
public void TakesDirectiveParams() { string xml = new Xambler( new Directives( new AddDirective("page"), new AddDirective("child-node") ) ).Xml(); Assert.NotNull(FromXPath(xml, "/page/child-node")); }
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>" ); }
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)); }
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); }); }
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 ); }
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 ); }
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"); }
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) ); }
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) ); }
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); } ); }
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); }
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) ); }
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) ); }
/// <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 ) { }
/// <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 ) { }
/// <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 ) { }