29 public void Encode(
object Object,
int? Indent, StringBuilder Json)
31 XmlElement Xml = (XmlElement)Object;
41 public static void Encode(XmlElement Xml,
int? Indent, StringBuilder Json)
50 AppendProperty(
"__name", Xml.LocalName, Indent, ref First, Json);
51 AppendProperty(
"__ns", Xml.NamespaceURI, Indent, ref First, Json);
53 foreach (XmlAttribute Attr
in Xml.Attributes)
54 AppendProperty(Attr.Name, Attr.Value, Indent, ref First, Json);
56 if (Xml.HasChildNodes)
58 Dictionary<string, ChunkedList<XmlElement>> ChildElements =
null;
59 StringBuilder InnerText =
null;
61 foreach (XmlNode N
in Xml.ChildNodes)
63 if (N is XmlElement E)
65 if (ChildElements is
null)
66 ChildElements =
new Dictionary<string, ChunkedList<XmlElement>>();
71 ChildElements[E.LocalName] = Elements;
76 else if (N is XmlText ||
77 N is XmlCDataSection ||
79 N is XmlSignificantWhitespace)
81 if (InnerText is
null)
82 InnerText =
new StringBuilder();
84 InnerText.Append(N.InnerText);
88 if (!(ChildElements is
null))
92 if (P.Value.Count == 1)
93 AppendProperty(P.Key, P.Value.FirstItem, Indent, ref First, Json);
95 AppendProperty(P.Key, P.Value, Indent, ref First, Json);
98 if (!(InnerText is
null))
100 AppendProperty(ChildElements.ContainsKey(
"value") ?
"__value" :
"value",
101 InnerText.ToString(), Indent, ref First, Json);
104 else if (!(InnerText is
null))
105 AppendProperty(
"value", InnerText.ToString(), Indent, ref First, Json);
122 private static void AppendProperty(
string Name,
object Value,
int? Indent,
123 ref
bool First, StringBuilder Json)
153 return ObjectType == typeof(XmlElement) ? Grade.Ok :
Grade.NotAtAll;
Helps with common JSON-related tasks.
static void Indent(StringBuilder Output, int NrTabs)
Appends an indentation to a string builder using tab characters.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Encodes an XML Element as a JSON object.
static void Encode(XmlElement Xml, int? Indent, StringBuilder Json)
Encodes an XmlElement to JSON.
void Encode(object Object, int? Indent, StringBuilder Json)
Encodes the Object to JSON.
XmlElementJsonEncoder()
Encodes an XML Element as a JSON object.
Grade Supports(Type ObjectType)
How well the JSON encoder encodes objects of type ObjectType .
A chunked list is a linked list of chunks of objects of type T .
Interface for encoding objects of certain types to JSON.