/// <summary> /// Adds XML node as a dictionary entry /// </summary> /// <param name="node">the node to convert</param> /// <param name="dic">the GSObject to add the converted node to</param> private void XmlToDictionaryEntry(XmlElement node, GSObject dic) { // Build a sorted list of key-value pairs // where key is case-sensitive nodeName // value is an ArrayList of string or XmlElement // so that we know whether the nodeName is an array or not. SortedList childNodeNames = new SortedList(); // Add in all nodes foreach (XmlNode cnode in node.ChildNodes) { if (cnode is XmlText) { StoreChildNode(childNodeNames, "value", cnode.InnerText); } else if (cnode is XmlElement) { StoreChildNode(childNodeNames, cnode.Name, cnode); } } foreach (string childname in childNodeNames.Keys) { ArrayList alChild = (ArrayList)childNodeNames[childname]; if (alChild.Count == 1) { OutputNode(childname, alChild[0], dic, true); } else { GSArray arr = new GSArray(); dic.Put(node.Name, arr); for (int i = 0; i < alChild.Count; i++) { GSObject cDic = new GSObject(); OutputNode(null, alChild[i], cDic, false); arr[i] = cDic; } dic.Put(childname, arr); } } }
/// <summary> /// /// </summary> /// <param name="childname"></param> /// <param name="alChild"></param> /// <param name="dictionary"></param> /// <param name="showNodeName"></param> private void OutputNode(string childname, object alChild, GSObject dictionary, bool showNodeName) { if (alChild == null) { if (showNodeName) { dictionary.Put(childname, String.Empty); } } else if (alChild is string) { if (showNodeName) { dictionary.Put(childname, alChild.ToString()); } } else { XmlToDictionaryEntry((XmlElement)alChild, dictionary); } }