public static string ToHTML(this IXML obj) { try { if (obj == null) { return(null); } XslCompiledTransform trans = GetTransform(obj); using (MemoryStream mem = obj.ToXMLStream()) { RemoveDescription(mem); mem.Seek(0, SeekOrigin.Begin); XmlReader xr = XmlReader.Create(mem); using (StringWriter textWriter = new StringWriter()) { using (XmlWriter xw = XmlWriter.Create(textWriter)) { trans.Transform(xr, xw); return(textWriter.ToString()); } } } } catch (Exception ex) { return(Error(ex)); } }
public void ContainsOnlyQueriedNodes() { IXML xml = new XMLCursor("<t6><z9 a='433'><item>a</item><item>b</item></z9><z9 a='432'><item>c</item></z9></t6>"); IXML root = xml.Nodes("/t6/z9[@a='433']")[0]; Assert.Empty(root.Values("/z9[@a='432']")); }
/// <summary> /// metodo de la interfaz IContainer donde agrega un elemento de tipo /// IXML en este caso un level a la lista de niveles. /// </summary> /// <param name="ixml"> recibe un IXML para agregar a la lista. </param> public void Add(IXML ixml) { if (ixml is Level) { this.ListLevel.Add((Level)ixml); } }
/// <summary> /// metodo de la interfaz IContainer donde agrega un elemento de tipo /// IXML en este caso una Screen a la lista de Screen. /// </summary> /// <param name="ixml"> recibe un IXML para agregar a la lista. </param> public void Add(IXML ixml) { if (ixml is Screen) { this.ScreenList.Add((Screen)ixml); } }
/// <summary> /// metodo de la interfaz IContainer donde agrega un elemento de tipo /// IXML en este caso un Element a la lista de Elements. /// </summary> /// <param name="ixml"> recibe un IXML para agregar a la lista. </param> public void Add(IXML ixml) { if (ixml is Element) { this.ElementList.Add((Element)ixml); } }
/// <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 ) { }
public void Show(IXML id) { current = result.FindIndex(s => s == id); if (current < 0) { Show(0); } Show(current); }
/// <summary> /// Texts, extracted from a xml with xpath. /// </summary> public XMLTexts(IXML xml, string xpath) : base(() => new Mapped <string, IText>( str => new Atoms.Text.TextOf(str), xml.Values(xpath) ), false ) { }
private void ShowHTML(IXML o) { webBrowser1.Navigate("about:blank"); webBrowser1.Document.OpenNew(true); webBrowser1.Document.Write(o.ToHTML()); webBrowser1.Refresh(); counter.Text = (current + 1) + "/" + result.Count; this.Show(); }
public void AppliesXpathToClonedNode() { IXML xml = new XMLCursor("<t6><z9 a='433'/></t6>"); IXML root = xml.Nodes("/t6")[0]; Assert.Equal( "433", root.Values("//z9/@a")[0] ); }
/// <summary> /// Number extracted from an xml using xpath. /// </summary> public XMLNumber(IXML xml, string xpath, IFormatProvider provider) { this.number = new ScalarOf <INumber>(() => new NumberOf( new XMLString(xml, xpath).Value(), provider ) ); }
/// <summary> /// A Response containing the given status, reason and a body from the given xml. /// </summary> public Of(int status, string reason, IXML body, params IMapInput[] extraParts) : base(() => new Response.Of( new Status(status), new Reason(reason), new Body(body), new Parts.Joined(extraParts) ), live: false ) { }
public static bool deserializar(IXML archivo, out object obj) { bool respuesta = false; if (archivo.Leer(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\persona.xml", out obj)) { respuesta = true; } return(respuesta); }
public static bool serializar(IXML archivo) { bool respuesta = false; if (archivo.Guardar(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\persona.xml")) { respuesta = true; } return(respuesta); }
private bool Match(IXML r, List <string> match, bool onlyName) { foreach (string s in match) { if (!r.Matches(s, onlyName)) { return(false); } } return(true); }
public static bool Deserializar(IXML x, out object o) { try { x.Leer("test.xml", out o); return(true); } catch (Exception) { return(false); } }
public static bool Serializar(IXML item) { try { item.Guardar(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\DatosClase20\textoXML.xml"); return(true); } catch (Exception e) { throw e; } }
public void PreservesDomStructureWhenXpath() { IXML doc = new XMLCursor( "<root><item1/><item2/><item3/></root>" ); IXML item = doc.Nodes("/root/item2")[0]; Assert.Equal( "root", item.Nodes("..")[0].Values("name()")[0]); }
/// <summary> /// A string in a document, retrieved by xpath. /// </summary> public XMLString(IXML xml, string xpath) : this ( xml, xpath, () => { throw new ArgumentException( $"Cannot retrieve single value with XPath '{xpath}', because it had no results in document{Environment.NewLine}'{xml.AsNode().ToString()}'." ); } ) { }
public static bool Serializar(IXML x) { try { x.Guardar("test.xml"); return(true); } catch (Exception) { return(false); throw; } }
public static bool Deserializar(IXML item, out object obj) { try { item.Leer(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\DatosClase20\textoXML.xml"); obj = item; return(true); } catch (Exception e) { throw e; } }
public static InfoPage Show(IXML obj, Command cmd = null, string cmdText = "Do") { InfoPage Instance = new InfoPage(obj); if (cmd != null) { Instance.ToolbarItems.Add(new ToolbarItem() { Command = cmd, CommandParameter = obj, Text = cmdText }); } return(Instance); }
/// <summary> /// The XML transformed to simple text, no XML document. /// </summary> /// <param name="xml">input XML</param> /// <returns>transformed output</returns> public string TransformedToText(IXML xml) { StringBuilder sb = new StringBuilder(); this.ErrorHandled(() => { using (var writer = new StringWriter(sb)) { this.Xslt().Transform( xml.AsNode().CreateReader(), Params(), writer ); } }); return(sb.ToString()); }
private static XslCompiledTransform GetTransform(IXML t) { if (t == null) { return(null); } if (Transforms.ContainsKey(t.GetType())) { return(Transforms[t.GetType()]); } XslCompiledTransform trans = new XslCompiledTransform(); Transforms.Add(t.GetType(), trans); LoadTransform?.Invoke(trans, t); if (trans.OutputSettings == null) { throw new Exception("No Transform found for " + t.GetType()); } return(trans); }
private InfoPage(IXML obj) { InitializeComponent(); BindingContext = this; Obj = obj; if (Obj is IOGLElement o) { Title = o.Name; } else if (Obj is Feature f) { Title = f.Name; } else if (Obj is DisplayPossession dp) { Title = dp.Name; } else { Title = "No Info"; } }
/// <summary> /// A string in a document, retrieved by xpath. /// </summary> internal XMLString(IXML xml, string xpath, Func <string> fallback) { this.result = new ScalarOf <string>(() => { var matches = xml.Values(xpath); var result = string.Empty; if (matches.Count < 1) { result = fallback(); } else if (matches.Count > 1) { throw new ArgumentException( $"Cannot retrieve single value with XPath '{xpath}' because it resulted in multiple values in document{Environment.NewLine}'{xml.AsNode().ToString()}'." ); } else { result = matches[0]; } return(result); }); }
/// <summary> /// The transformed XML. /// </summary> /// <param name="xml">input XML</param> /// <returns>transformed output</returns> public IXML Transformed(IXML xml) { var transformed = new XDocument(); var output = new StringBuilder(); var settings = new XmlWriterSettings(); settings.Indent = false; settings.ConformanceLevel = ConformanceLevel.Auto; this.ErrorHandled(() => { using (XmlWriter writer = XmlWriter.Create(output, settings)) { this.Xslt().Transform( xml.AsNode().CreateReader(), Params(), writer ); } }); return(new XMLCursor(output.ToString())); }
/// <summary> /// A string in a document, retrieved by xpath. /// </summary> public XMLString(IXML xml, string xpath, string def) : this(xml, xpath, () => def) { }
public string Convert(IXML obj) { return(obj.ToHTML()); }
/// <summary> /// Strings in a document, retrieved by xpath. /// </summary> public XMLStrings(string xpath, IXML xml) : base( () => xml.Values(xpath), false ) { }