Ejemplo n.º 1
0
        EncapsulateNode EncapsulateString(string meta, List <string> data, string htmlData, bool header = true, int index = 0)
        {
            string hd     = htmlData;
            int    idx    = index;
            string prefix = "<";

            data.Insert(idx, prefix + meta + ">");
            while (hd.IndexOf("<") != -1)
            {
                while (hd.IndexOf("</") == hd.IndexOf("<") && hd.IndexOf("<") != -1)
                {
                    hd = hd.Substring(hd.IndexOf(">") + 1);
                }
                hd = hd.Substring(hd.IndexOf("<") + 1);
                if (isElement("table", hd))
                {
                    if (header)
                    {
                        hd = hd.Substring(hd.IndexOf("<td"));
                        hd = hd.Substring(hd.IndexOf(">") + 1);
                        var dd = hd.Substring(0, hd.IndexOf("</td>"));
                        hd = hd.Substring(dd.Length);
                        dd = getElementString(dd);
                        EncapsulateNode result = EncapsulateString(dd, data, hd, false, idx + 1);
                        hd  = result.hd;
                        idx = result.idx;
                    }
                    else
                    {
                        string td = hd.Substring(0, hd.IndexOf("</table"));
                        hd = hd.Substring(hd.IndexOf("</table>") + 7);
                        while (td.IndexOf("<td") != -1)
                        {
                            td = td.Substring(td.IndexOf("<td"));
                            var rr = td.Substring(0, td.IndexOf("</td>") + 5);
                            td = td.Substring(rr.Length);
                            rr = rr.Substring(rr.IndexOf(">") + 1);
                            rr = rr.Substring(0, rr.IndexOf("</td>"));
                            string[] dd = getInfoStrings(rr);
                            data.Insert(++idx, "<" + dd[0] + ">");
                            data.Insert(++idx, dd[1]);
                            data.Insert(++idx, "</" + dd[0] + ">");
                        }
                        break;
                    }
                }
            }
            data.Insert(++idx, prefix + "/" + meta + ">");
            EncapsulateNode ret = new EncapsulateNode();

            ret.hd  = hd;
            ret.idx = idx;
            return(ret);
        }
Ejemplo n.º 2
0
        private string[] GenerateXMLfromString(string data)
        {
            List <string> ret = new List <string>();

            data = data.ToLower();
            data = data.Substring(data.IndexOf("<table") + 5);

            ret.Insert(0, "<INVOICE>");

            ret.Insert(1, "<HEADER>");
            EncapsulateNode result = EncapsulateString("SERIAL", ret, data, false, ret.Count);

            data = result.hd;
            string header = string.Empty;

            for (int i = 0; i < 8; i++)
            {
                data = data.Substring(data.IndexOf("<table"));
                string t = data.Substring(0, data.IndexOf("</table") + 8);
                data = data.Substring(t.Length);
                if (i == 1 || i == 2 || i == 4 || i == 5)
                {
                    string r = t.Substring(0, t.IndexOf("</tr>") + 5);
                    t       = t.Substring(r.Length);
                    t       = r.Replace("</tr>", "</table><table>") + t;
                    header += t;
                }
                else if (i == 3)
                {
                    string r = t;
                    data = data.Substring(data.IndexOf("<table"));
                    t    = data.Substring(0, data.IndexOf("</table") + 8);
                    data = data.Substring(t.Length);

                    r = r.Replace("</table>", string.Empty);
                    t = t.Substring(t.IndexOf('>') + 1);
                    t = r + t;

                    r       = t.Substring(0, t.IndexOf("</tr>") + 5);
                    t       = t.Substring(r.Length);
                    t       = r.Replace("</tr>", "</table><table>") + t;
                    header += t;
                }
                else
                {
                    header += t;

                    data    = data.Substring(data.IndexOf("<table"));
                    t       = data.Substring(0, data.IndexOf("</table") + 8);
                    header += t;
                    data    = data.Substring(t.Length);
                }
            }
            data = data.Substring(data.IndexOf("<table"));
            EncapsulateString("INFO", ret, header, true, ret.Count);
            ret.Insert(ret.Count, "</HEADER>");

            data = data.Substring(data.IndexOf("<table"));
            data = data.Substring(0, data.LastIndexOf("</table>") + 8);

            string[] footer = new string[8];
            for (int i = 0; i < 8; i++)
            {
                string t = data.Substring(data.LastIndexOf("<table"));
                t             = t.Substring(0, t.IndexOf("</table>") + 8);
                data          = data.Substring(0, data.LastIndexOf("<table"));
                data          = data.Substring(0, data.LastIndexOf("</table>") + 8);
                footer[7 - i] = t;
            }
            string footerTitle = getElementString(footer[0]);
            string footerData  = string.Empty;
            string temp        = footer[1];

            temp        = temp.Substring(0, temp.IndexOf("<tr")) + temp.Substring(temp.IndexOf("</tr>") + 5);
            temp        = temp.Substring(0, temp.IndexOf("</tr")) + "</table><table>" + temp.Substring(temp.IndexOf("</tr>"));
            footerData += temp;
            temp        = footer[2];
            temp        = temp.Substring(0, temp.IndexOf("</tr")) + "</table><table>" + temp.Substring(temp.IndexOf("</tr>"));
            footerData += temp;
            temp        = footer[4];
            temp        = temp.Substring(0, temp.IndexOf("</tr")) + "</table><table>" + temp.Substring(temp.IndexOf("</tr>"));
            footerData += temp;
            temp        = footer[5];
            temp        = temp.Substring(0, temp.IndexOf("</tr")) + "</table><table>" + temp.Substring(temp.IndexOf("</tr>"));
            footerData += temp;
            temp        = footer[6];
            temp        = temp.Substring(0, temp.IndexOf("</tr")) + "</table><table>" + temp.Substring(temp.IndexOf("</tr>"));
            footerData += temp;
            temp        = getElementString(footer[7]);
            temp        = "<table><td>INFO</td></table><table><td><span>DATE</span><span>" + temp + "</span></td></table>";
            footerData += temp;

            string productTitle = data.Substring(0, data.IndexOf("</table>") + 8);

            data         = data.Substring(data.IndexOf("</table"));
            data         = data.Substring(data.IndexOf("<table"));
            productTitle = getElementString(productTitle);

            string products = "";

            while (data.IndexOf("<div") != -1)
            {
                string product = string.Empty;
                string s       = data.Substring(0, data.IndexOf("<div"));
                data = data.Substring(data.IndexOf("<div"));
                s    = s.Replace("/table", "/tr");

                string e = string.Empty;
                if (data.IndexOf("</div") != -1)
                {
                    e = data.Substring(0, data.IndexOf("</div>") + 5);
                }
                else
                {
                    e = data;
                }
                data = data.Substring(e.Length);
                if (e.IndexOf("table") != -1)
                {
                    e = e.Substring(e.IndexOf("<table") + 6);
                    e = e.Substring(0, e.LastIndexOf("</table"));

                    while (e.IndexOf("<table") != -1)
                    {
                        string se = e.Substring(0, e.IndexOf("<table"));
                        //string espan = se.Substring(se.IndexOf("<span"));
                        //se = se.Substring(0, se.IndexOf("<span"));
                        se = se.Substring(0, se.LastIndexOf("<td"));
                        string ee = e.Substring(e.IndexOf("<table"));
                        e = se + ee;
                        e = e.Replace("table", "tr");
                    }
                }

                product   = s + e + "</table>";
                product   = product.Substring(0, product.IndexOf("</td>")) + "</td></table><table>" + product.Substring(product.IndexOf("</td>") + 5);
                products += product;
            }

            EncapsulateString(productTitle, ret, products, true, ret.Count);

            EncapsulateString(footerTitle, ret, footerData, true, ret.Count);

            ret.Insert(ret.Count, "</INVOICE>");
            return(ret.ToArray());
        }