public void RejectsValuesWithInvalidXPath() { try { var v = new XMLCursor("<root><a><x attr='test'>1</x></a><a><x>2</x></a></root>").Values("//[x")[0]; Assert.True(false, "expected an Exception, should not get here"); } catch (Exception ex) { Assert.Contains( "Invalid XPath expression", ex.Message); } }
public void HasXml() { var expected = new XMLCursor("<root><importantXmlData /></root>"); Assert.Equal( expected.AsNode().ToString(), new XmlResponse( new FkWire(req => new Response.Of( new Body(expected) ) ) ).AsNode().ToString() ); }
public void FindsDocumentNodes() { IXML doc = new XMLCursor( new InputOf( "<root><a><x attr='test'>1</x></a><a><x>2</x></a></root>" ) ); Assert.True( new Atoms.Enumerable.LengthOf( doc.Nodes("//a") ).Value() == 2 ); }
public void FindsDocumentValues() { IXML doc = new XMLCursor( new InputOf( "<root><a><x attr='test'>1</x></a><a><x>2</x></a></root>" ) ); Assert.True( doc .Nodes("/root/a")[0] .Values("x/@attr")[0] == "test" ); }
public void UnDo() { if (this._undoHandler == null) { throw new ApplicationException("No Undo-Handler attached, but Undo invoked!"); } XMLCursor xMLCursor = this._undoHandler.Undo(); if (xMLCursor != null) { this._cursor.StartPos.CursorSetzen(xMLCursor.StartPos.AktNode, xMLCursor.StartPos.PosAmNode, xMLCursor.StartPos.PosImTextnode); this._cursor.EndPos.CursorSetzen(xMLCursor.EndPos.AktNode, xMLCursor.EndPos.PosAmNode, xMLCursor.EndPos.PosImTextnode); } this.ContentChanged(); }
public void FindsNodesWithBuiltinNamespace() { IXML doc = new XMLCursor( "<html xmlns='http://www.w3.org/1999/xhtml'><div>\u0443\u0440\u0430!</div></html>" ); Assert.Equal( 1, doc.Nodes("/xhtml:html/xhtml:div").Count ); Assert.Equal( 1, doc.Nodes("//xhtml:div[.='\u0443\u0440\u0430!']").Count ); }
public void FindsDocumentNodesWithXpath() { IXML doc = new XMLCursor( new Yaapii.Atoms.IO.InputOf( "<root><a><x>1</x></a><a><x>2</x></a></root>" ) ); Assert.Equal( 2, doc.Nodes("//a").Count ); Assert.Equal( "1", doc.Nodes("/root/a")[0].Values("x/text()")[0] ); }
public void FindsNodesWithCustomNamespace() { IXML doc = new XMLCursor( "<a xmlns='urn:foo'><b>\u0433!</b></a>" ); doc = doc.WithNamespace("f", "urn:foo"); Assert.Single( doc.Nodes("/f:a/f:b[.='\u0433!']") ); Assert.Equal( "\u0433!", doc.Values("//f:b/text()")[0] ); }
public void WorksWithXNode() { var xml = new XMLCursor( "<root><node><leaf name='test' /></node></root>" ).AsNode(); var modifiedXml = new XMLPatched( xml, new Directives() .Xpath("//root/node/leaf") .Attr("id", "123") .Add("content") .Set("testContent") ); Assert.NotEmpty( modifiedXml.Values("/root/node/leaf[@id='123']/content/text()") ); }
public void ReturnsXmlInExceptionMessage() { var xml = new XMLCursor( new ResourceOf( "Resources/simple.xml", this.GetType() ).Stream() ); try { new XMLString(xml, "root/complex").Value(); } catch (Exception ex) { Assert.Contains("" + "Cannot retrieve single value with XPath 'root/complex', because it had no results in document\r\n'\r\n<root>\r\n <simple>hello</simple>\r\n</root>\r\n'.", ex.Message ); } }
public virtual bool AktionDelete( XMLEditor.UndoSnapshotSetzenOptionen undoSnapshotSetzen) { if (!this.AktionenMoeglich || this.IstRootNodeSelektiert) { return(false); } if (undoSnapshotSetzen == XMLEditor.UndoSnapshotSetzenOptionen.ja) { this._undoHandler.SnapshotSetzen(de.springwald.xml.ResReader.Reader.GetString("AktionLoeschen"), this._cursor); } XMLCursor cursor = this._cursor; cursor.SelektionOptimieren(); XMLCursorPos neueCursorPosNachLoeschen; if (!cursor.SelektionLoeschen(out neueCursorPosNachLoeschen)) { return(false); } this._cursor.BeideCursorPosSetzen(neueCursorPosNachLoeschen.AktNode, neueCursorPosNachLoeschen.PosAmNode, neueCursorPosNachLoeschen.PosImTextnode); this.ContentChanged(); return(true); }
private void StartUndEndeDerSelektionBestimmen(ref int selektionStart, ref int selektionLaenge) { XMLCursor cursorOptimiert = base._xmlEditor.CursorOptimiert; if (cursorOptimiert.StartPos.AktNode == base._xmlNode) { switch (cursorOptimiert.StartPos.PosAmNode) { case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag: case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag: selektionStart = 0; selektionLaenge = this.AktuellerInhalt.Length; break; case XMLCursorPositionen.CursorInDemLeeremNode: case XMLCursorPositionen.CursorHinterDemNode: selektionStart = -1; selektionLaenge = 0; break; case XMLCursorPositionen.CursorVorDemNode: case XMLCursorPositionen.CursorInnerhalbDesTextNodes: if (cursorOptimiert.StartPos.PosAmNode == XMLCursorPositionen.CursorInnerhalbDesTextNodes) { selektionStart = Math.Max(0, cursorOptimiert.StartPos.PosImTextnode); } else { selektionStart = 0; } if (cursorOptimiert.EndPos.AktNode == base._xmlNode) { switch (cursorOptimiert.EndPos.PosAmNode) { case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag: case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag: case XMLCursorPositionen.CursorHinterDemNode: selektionLaenge = Math.Max(0, this.AktuellerInhalt.Length - selektionStart); break; case XMLCursorPositionen.CursorInDemLeeremNode: selektionStart = -1; selektionLaenge = 0; break; case XMLCursorPositionen.CursorInnerhalbDesTextNodes: selektionLaenge = Math.Max(0, cursorOptimiert.EndPos.PosImTextnode - selektionStart); break; case XMLCursorPositionen.CursorVorDemNode: selektionLaenge = 0; break; default: throw new ApplicationException("Unbekannte XMLCursorPosition.EndPos.PosAmNode '" + cursorOptimiert.EndPos.PosAmNode + "'B"); } } else if (cursorOptimiert.EndPos.AktNode.ParentNode == cursorOptimiert.StartPos.AktNode.ParentNode) { selektionLaenge = Math.Max(0, this.AktuellerInhalt.Length - selektionStart); } else { selektionStart = 0; selektionLaenge = this.AktuellerInhalt.Length; } break; default: throw new ApplicationException("Unbekannte XMLCursorPosition.StartPos.PosAmNode '" + cursorOptimiert.StartPos.PosAmNode + "'A"); } } else if (cursorOptimiert.EndPos.AktNode == base._xmlNode) { switch (cursorOptimiert.EndPos.PosAmNode) { case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag: case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag: case XMLCursorPositionen.CursorHinterDemNode: selektionStart = 0; selektionLaenge = this.AktuellerInhalt.Length; break; case XMLCursorPositionen.CursorInDemLeeremNode: selektionStart = -1; selektionLaenge = 0; break; case XMLCursorPositionen.CursorInnerhalbDesTextNodes: if (cursorOptimiert.EndPos.AktNode.ParentNode == cursorOptimiert.StartPos.AktNode.ParentNode) { selektionStart = 0; selektionLaenge = Math.Max(0, cursorOptimiert.EndPos.PosImTextnode); } else { selektionStart = 0; selektionLaenge = this.AktuellerInhalt.Length; } break; case XMLCursorPositionen.CursorVorDemNode: selektionStart = -1; selektionLaenge = 0; break; default: throw new ApplicationException("Unbekannte XMLCursorPosition.EndPos.PosAmNode '" + cursorOptimiert.EndPos.PosAmNode + "'X"); } } else if (base._xmlEditor.CursorOptimiert.IstNodeInnerhalbDerSelektion(base._xmlNode)) { selektionStart = 0; selektionLaenge = this.AktuellerInhalt.Length; } }
public void SnapshotSetzen(string snapShotName, XMLCursor cursor) { this._undoSchritte[this._pos].SnapShotName = snapShotName; this._undoSchritte[this._pos].CursorVorher = cursor; }