/// <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> /// 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()); }
/// <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> 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> /// 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()}'." ); } ) { }
/// <summary> /// Validation of XML documents by XSD schema validation /// </summary> /// <param name="xml">The XML to be validate</param> /// <param name="schema">A XSD schema to validate with</param> public XSDErrors(IXML xml, IXML schema) : this( new ScalarOf <XDocument>(() => xml.AsNode().Document), new ScalarOf <string>(() => schema.AsNode().ToString()) ) { }
/// <summary> /// Adds a xml body to a request. Sets the Content-Type to 'application/xml' /// </summary> public Body(IXML xml) : this( new TextOf(() => xml.AsNode().ToString()), "application/xml" ) { }