Example #1
0
        public static void TestData()
        {
            string      xmlData = File.ReadAllText(@"c:\temp\abc.xml");
            GWDataTable mytable = new GWDataTable();

            mytable.loadXml(xmlData);
            for (int i = 0; i < mytable.length(); i++)
            {
                GWRowInterface col = mytable.GetRow(i);
                foreach (KeyValuePair <string, string> entry in col.entrySet())
                {
                    Console.WriteLine(entry.Key + ":" + entry.Value);
                }
            }
        }
Example #2
0
        public void WriteXml(StringWriter finalsw, string nodename)
        {
            int colstart = 0;

            if (nodename == "")
            {
                nodename = "xmlDS";
            }
            else
            {
                colstart = 1;
            }
            StringWriter sw = new StringWriter();

            for (int i = 0; i < data.Count; i++)
            {
                GWRowInterface col = data[i];
                Dictionary <string, string> item = col.ToArray();
                string header = "";
                string footer = "";
                string Retval = "";

                foreach (KeyValuePair <string, string> entry in item)
                {
                    string key   = entry.Key;
                    string value = entry.Value;
                    if (value != null)
                    {
                        value = value.ToString().Replace("&", "%26");

                        String[] a = key.Split('.');
                        if (header == "")
                        {
                            for (int j = colstart; j < a.Length - 1; j++)
                            {
                                string tabs = repeat(" ", j);
                                if (!(a[j] == nodename))
                                {
                                    header = header + tabs + "<" + a[j] + ">\n";
                                }
                            }
                        }

                        if (footer == "")
                        {
                            for (int j = a.Length - 2; j >= colstart; j--)
                            {
                                // int count=-1 * j + a.length;
                                int    count = j;
                                string tabs  = repeat(" ", count);
                                if (!(a[j] == nodename))
                                {
                                    footer = footer + tabs + "</" + a[j] + ">\n";
                                }
                            }
                        }
                        Retval = Retval + repeat(" ", a.Length) + "<" + a[a.Length - 1] + ">" + value + "</" + a[a.Length - 1] + ">\n";
                    }
                    //    System.out.println(key + " " + value);
                }

                sw.Write(header);
                sw.Write(Retval);
                sw.Write(footer);
            }
            finalsw.Write("<?xml version=\"1.0\"?>\n");
            finalsw.Write("<" + nodename + ">\n");
            finalsw.Write(sw.ToString());
            finalsw.Write("</" + nodename + ">\n");
        }
Example #3
0
        public GWDataTable find(string qlwhereclause, string _defObj)
        {
            GWQL             xPathTester = new GWQL(qlwhereclause);
            GWQLXPathBuilder myxpath     = new GWQLXPathBuilder();
            string           whereclause = "";

            try
            {
                whereclause = xPathTester.getCommand(myxpath);
            }
            catch (GWException e) { throw e; }
            string xmldata = toXml();
            //System.out.println(xmldata);
            GWDataTable retTable = new GWDataTable("", tablename);

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmldata);
                string      qry   = "//xmlDS/" + tablename + "[" + whereclause + "]";
                XmlNodeList nodes = doc.DocumentElement.SelectNodes(qry);

                //System.out.println("Length is: " + nodes.getLength());
                foreach (XmlNode xn in nodes)
                {
                    Dictionary <string, string> theitem = new Dictionary <string, string>();
                    //string firstName = xn["FirstName"].InnerText;
                    //string lastName = xn["LastName"].InnerText;
                    XmlNodeList children = xn.ChildNodes;
                    foreach (XmlNode thechild in children)
                    {
                        //thechild.Name;
                        //thechild.InnerText;
                        theitem.Add(tablename + "." + thechild.Name, thechild.InnerText);
                    }
                    if (theitem.Count > 0)
                    {
                        Type type = Type.GetType(_defObj);
                        if (type == null)
                        {
                            System.Reflection.Assembly currentAssem = System.Reflection.Assembly.GetEntryAssembly();
                            Type CorrectType = null;
                            foreach (Type t1 in currentAssem.GetTypes())
                            {
                                if (t1.Name == _defObj)
                                {
                                    CorrectType = t1;
                                }
                            }
                            type = CorrectType;
                        }
                        if (type != null)
                        {
                            GWRowInterface therow = (GWRowInterface)Activator.CreateInstance(type, theitem);
                            retTable.Add(therow);
                        }
                    }
                }
            }
            catch (Exception e) { Console.WriteLine(e.StackTrace); }
            return(retTable);
        }
Example #4
0
 public void Add(GWRowInterface newrow)
 {
     data.Add(newrow);
 }