public void Substitute_Cdata() { var sub = new ParameterSubstitution(); sub.AddIndexedParameters(new object[] { "first & second > third", true, new DateTime(2015, 1, 1) }); var newQuery = sub.Substitute("<Item><name><![CDATA[@0]]></name><is_current>${1}</is_current><date>${2}</date></Item>", ElementFactory.Local.LocalizationContext); Assert.AreEqual("<Item><name><![CDATA[first & second > third]]></name><is_current>1</is_current><date>2015-01-01T00:00:00</date></Item>", newQuery); }
/// <summary> /// Converts an AML node into a query which can be converted to other forms (e.g. SQL, OData, ...) /// </summary> /// <param name="xml">XML data</param> /// <param name="context">Localization context for parsing and formating data</param> /// <param name="args">Arguments to substitute into the query</param> public static QueryItem FromXml(string xml, IServerContext context, params object[] args) { return(FromXml(w => { var sub = new ParameterSubstitution(); sub.AddIndexedParameters(args); sub.Substitute(xml, context, w); }, context)); }
public void Substitute_SavedSearchParameter() { var sub = new ParameterSubstitution(); sub.AddIndexedParameters(new object[] { "first & second > third", true, new DateTime(2015, 1, 1) }); var newQuery = sub.Substitute("<Item><name>@{0}</name><is_current>@{1}</is_current><date>@{2}</date></Item>", ElementFactory.Local.LocalizationContext); Assert.AreEqual("<Item><name>first & second > third</name><is_current>1</is_current><date>2015-01-01T00:00:00</date></Item>", newQuery); }
/// <summary> /// Returns a new <see cref="Item"/> with the AML body. /// </summary> /// <param name="aml">AML to populate the item with</param> /// <param name="args">Parameters to be injected into the query</param> public Item newItemFromAml(string aml, params object[] args) { var dom = NewXmlDocument(); if (args?.Length > 0) { using (var writer = dom.CreateNavigator().AppendChild()) { var sub = new ParameterSubstitution(); sub.AddIndexedParameters(args); sub.Substitute(aml, LocalizationContext, writer); } } else { dom.LoadXml(aml); } return(new Item(this, dom)); }