Based on the C # dynamic with XML example , I modified DynamicXml.cs and parsed my xml string. the modified part is as follows
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = null;
if (binder.Name == "Controls")
result = new DynamicXml(_elements.Elements());
else if (binder.Name == "Count")
result = _elements.Count;
else
{
var attr = _elements[0].Attribute(
XName.Get(binder.Name));
if (attr != null)
result = attr.Value;
else
{
var items = _elements.Descendants(
XName.Get(binder.Name));
if (items == null || items.Count() == 0)
return false;
result = new DynamicXml(items);
}
}
return true;
}
Xml line for parsing:
"< View runat='server' Name='Doc111'>" +
"< Caption Name='Document.ConvertToPdf' Value='Allow Conversion to PDF'></ Caption>" +
"< Field For='Document.ConvertToPdf' ReadOnly='False' DisplayAs='checkbox' EditAs='checkbox'></ Field>" +
"< Field For='Document.Abstract' ReadOnly='False' DisplayAs='label' EditAs='textinput'></ Field>" +
"< Field For='Document.FileName' ReadOnly='False' DisplayAs='label' EditAs='textinput'></ Field>" +
"< Field For='Document.KeyWords' ReadOnly='False' DisplayAs='label' EditAs='textinput'></ Field>" +
"< FormButtons SaveCaption='Save' CancelCaption='Cancel'></ FormButtons>" +
"</ View>";
dynamic form = new DynamicXml (markup_fieldsOnly);
Is there a way to serialize the contents of this dynamic object (a pair of name values inside the dynamic) form as a JSON object and sent to the client side (browser)?
user306041
source
share