BBGamelib.NSCollectionUtils.ParseDictionary C# (CSharp) Method

ParseDictionary() public static method

public static ParseDictionary ( XmlNode node ) : NSDictionary
node System.Xml.XmlNode
return NSDictionary
		public static NSDictionary ParseDictionary(XmlNode node)
		{
			XmlNodeList children = node.ChildNodes;
			if (children.Count % 2 != 0)
			{
				throw new DataMisalignedException("Dictionary elements must have an even number of child nodes");
			}
			
			NSDictionary dict = new NSDictionary();
			
			for (int i = 0; i < children.Count; i += 2)
			{
				XmlNode keynode = children[i];
				XmlNode valnode = children[i + 1];
				
				if (keynode.Name != "key")
				{
					throw new ApplicationException("expected a key node");
				}
				
				object result = Parse(valnode);
				
				if (result != null)
                {
                    dict[keynode.InnerText] = result;
                    
                }
            }
            
            return dict;
		}

Usage Example

Beispiel #1
0
        public static NSDictionary DictionaryWithContentsOfString(string text)
        {
            if (text == null || text.Length == 0)
            {
                return(null);
            }

            text = System.Text.RegularExpressions.Regex.Replace(text, "<.*\\.dtd\">", string.Empty);
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ProhibitDtd    = false;
            settings.ValidationType = ValidationType.None;
            XmlDocument xmlDoc = new XmlDocument();

            using (StringReader sr = new StringReader(text))
                using (XmlReader reader = XmlReader.Create(sr, settings))
                {
                    xmlDoc.Load(reader);
                }

//			XmlDocument xmlDoc = new XmlDocument();
//			xmlDoc.LoadXml (text);

            XmlNode rootNode = xmlDoc.DocumentElement.ChildNodes[0];

            if (rootNode.Name != "dict")
            {
                return(null);
            }
            NSDictionary dict = NSCollectionUtils.ParseDictionary(rootNode);

            return(dict);
        }
All Usage Examples Of BBGamelib.NSCollectionUtils::ParseDictionary