Exemplo n.º 1
0
        /// <summary>
        /// Parsen der OData-Struktur und Ausgabe der Tabelle
        /// </summary>
        /// <param name="respXml">Resp xml.</param>
        public void buildTable(string respXml)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(respXml);

            //xmlDoc durch XmlNamespaceManager parsen
            XmlNamespaceManager xmlManager = new XmlNamespaceManager(xmlDoc.NameTable);

            xmlManager.AddNamespace("atom", "http://www.w3.org/2005/Atom");
            xmlManager.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
            xmlManager.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
            xmlManager.AddNamespace("sap", "http://www.sap.com/Protocols/SAPData");
            xmlManager.AddNamespace("base", "HTTP://SCDECC.SCDINTERN.DE:8000/sap/opu/sdata/SCD/ZGEN_MI_EMPLOYEES/");

            XmlNodeList elements = xmlDoc.DocumentElement.SelectNodes("./atom:entry", xmlManager);

            Console.WriteLine("test count: " + elements.Count.ToString());

            List <string> listName        = new List <string>();
            List <string> listPernr       = new List <string>();
            List <string> listTeilbereich = new List <string>();
            List <string> listOrg         = new List <string>();
            List <NSData> listImg         = new List <NSData>();

            foreach (XmlNode element in elements)
            {
                XmlNodeList propName = element.SelectSingleNode("./atom:content/m:properties/d:ENAME", xmlManager).ChildNodes;
                foreach (XmlNode name in propName)
                {
                    listName.Add(name.InnerText.ToString());
                }

                XmlNodeList propPernr = element.SelectSingleNode("./atom:content/m:properties/d:PERNR", xmlManager).ChildNodes;
                foreach (XmlNode pernr in propPernr)
                {
                    listPernr.Add(pernr.InnerText.ToString());
                }

                XmlNodeList propTeilbereich = element.SelectSingleNode("./atom:content/m:properties/d:BTRTX", xmlManager).ChildNodes;
                foreach (XmlNode teilbereich in propTeilbereich)
                {
                    listTeilbereich.Add(teilbereich.InnerText.ToString());
                }

                XmlNodeList propOrg = element.SelectSingleNode("./atom:content/m:properties/d:ORGTX", xmlManager).ChildNodes;
                foreach (XmlNode org in propOrg)
                {
                    listOrg.Add(org.InnerText.ToString());
                }

                XmlNodeList propImg = element.SelectSingleNode("./atom:content/m:properties/d:PORTRAIT_IMG", xmlManager).ChildNodes;
                foreach (XmlNode img in propImg)
                {
                    string imgBase64 = img.Value.Replace("data:image/jpeg;base64,", "");

                    while ((imgBase64.Length % 4) != 0)
                    {
                        imgBase64 += "=";
                        Console.WriteLine("imgBase64 nicht mod 4!");
                    }
                    byte[] imgBytes = Convert.FromBase64String(imgBase64);
                    NSData data     = NSData.FromArray(imgBytes);
                    listImg.Add(data);
                }
            }
            tableViewSource  = new TableViewSource(this, listName, listPernr, listTeilbereich, listOrg, listImg);
            tableView.Source = tableViewSource;
        }
        /// <summary>
        /// Parsen der OData-Struktur und Ausgabe der Tabelle
        /// </summary>
        /// <param name="respXml">Resp xml.</param>
        public void buildTable(string respXml)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(respXml);

            //xmlDoc durch XmlNamespaceManager parsen
            XmlNamespaceManager xmlManager = new XmlNamespaceManager(xmlDoc.NameTable);
            xmlManager.AddNamespace("atom" 	, "http://www.w3.org/2005/Atom");
            xmlManager.AddNamespace("d" 	, "http://schemas.microsoft.com/ado/2007/08/dataservices");
            xmlManager.AddNamespace("m"		, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
            xmlManager.AddNamespace("sap"	, "http://www.sap.com/Protocols/SAPData");
            xmlManager.AddNamespace("base"	, "HTTP://SCDECC.SCDINTERN.DE:8000/sap/opu/sdata/SCD/ZGEN_MI_EMPLOYEES/");

            XmlNodeList elements = xmlDoc.DocumentElement.SelectNodes("./atom:entry" , xmlManager);
            Console.WriteLine("test count: " + elements.Count.ToString());

            List <string> listName = new List<string>();
            List <string> listPernr = new List<string>();
            List <string> listTeilbereich = new List<string>();
            List <string> listOrg = new List<string>();
            List <NSData> listImg = new List<NSData>();

            foreach (XmlNode element in elements)
            {
                XmlNodeList propName = element.SelectSingleNode("./atom:content/m:properties/d:ENAME" , xmlManager).ChildNodes;
                foreach(XmlNode name in propName)
                {
                    listName.Add(name.InnerText.ToString());
                }

                XmlNodeList propPernr = element.SelectSingleNode("./atom:content/m:properties/d:PERNR" , xmlManager).ChildNodes;
                foreach(XmlNode pernr in propPernr)
                {
                    listPernr.Add(pernr.InnerText.ToString());
                }

                XmlNodeList propTeilbereich = element.SelectSingleNode("./atom:content/m:properties/d:BTRTX" , xmlManager).ChildNodes;
                foreach(XmlNode teilbereich in propTeilbereich)
                {
                    listTeilbereich.Add(teilbereich.InnerText.ToString());
                }

                XmlNodeList propOrg = element.SelectSingleNode("./atom:content/m:properties/d:ORGTX" , xmlManager).ChildNodes;
                foreach(XmlNode org in propOrg)
                {
                    listOrg.Add(org.InnerText.ToString());
                }

                XmlNodeList propImg = element.SelectSingleNode("./atom:content/m:properties/d:PORTRAIT_IMG" , xmlManager).ChildNodes;
                foreach(XmlNode img in propImg)
                {
                    string imgBase64 = img.Value.Replace("data:image/jpeg;base64,","");

                    while((imgBase64.Length % 4) != 0)
                    {
                        imgBase64 += "=";
                        Console.WriteLine("imgBase64 nicht mod 4!");
                    }
                    byte[] imgBytes = Convert.FromBase64String(imgBase64);
                    NSData data = NSData.FromArray(imgBytes);
                    listImg.Add(data);
                }
            }
            tableViewSource = new TableViewSource(this , listName, listPernr, listTeilbereich, listOrg, listImg);
            tableView.Source = tableViewSource;
        }