Example #1
6
        public UssdRequestMessage GenerateMessageObject()
        {
            UssdRequestMessage message = new UssdRequestMessage(); ;
            XmlDocument document = new XmlDocument();
            var xmlFormed = _xmlDocument.Replace("&lt;", "<").Replace("&quot;", "\"").Replace("&gt;", ">");
            //throw new Exception(xmlFormed);
            document.LoadXml(xmlFormed);
            XmlNodeList nodes;
            try
            {
                nodes = document.SelectNodes("//methodCall/params/param/value/struct/member");
                if (nodes.Count > 0)
                {
                    message = new UssdRequestMessage();
                    foreach (XmlNode node in nodes)
                    {
                        XmlDocument nodedoc = new XmlDocument();
                        string modif = "<modified>" + node.InnerXml + "</modified>";
                        nodedoc.LoadXml(modif);
                        var resultName = nodedoc.SelectSingleNode("modified/name").InnerText;
                        var resultValue = nodedoc.SelectSingleNode("modified/value").InnerText;
                        PropertyInfo prop = message.GetType().GetProperty(resultName);
                        if (prop != null)
                        {
                            var val = Convert.ChangeType(resultValue, prop.PropertyType);
                            prop.SetValue(message, val, null);
                        }

                    }
                }
            }
            catch (Exception ex) { }

            return message;
        }
Example #2
0
        public UssdRequestMessage GenerateMessageObject()
        {
            UssdRequestMessage message  = new UssdRequestMessage();;
            XmlDocument        document = new XmlDocument();
            var xmlFormed = _xmlDocument.Replace("&lt;", "<").Replace("&quot;", "\"").Replace("&gt;", ">");

            //throw new Exception(xmlFormed);
            document.LoadXml(xmlFormed);
            XmlNodeList nodes;

            try
            {
                nodes = document.SelectNodes("//methodCall/params/param/value/struct/member");
                if (nodes.Count > 0)
                {
                    message = new UssdRequestMessage();
                    foreach (XmlNode node in nodes)
                    {
                        XmlDocument nodedoc = new XmlDocument();
                        string      modif   = "<modified>" + node.InnerXml + "</modified>";
                        nodedoc.LoadXml(modif);
                        var          resultName  = nodedoc.SelectSingleNode("modified/name").InnerText;
                        var          resultValue = nodedoc.SelectSingleNode("modified/value").InnerText;
                        PropertyInfo prop        = message.GetType().GetProperty(resultName);
                        if (prop != null)
                        {
                            var val = Convert.ChangeType(resultValue, prop.PropertyType);
                            prop.SetValue(message, val, null);
                        }
                    }
                }
            }
            catch (Exception ex) { }

            return(message);
        }