Esempio n. 1
0
        public void insertElementAt(string strElement, string[,] arrAttributes, string strAttributes, string strText, int iElemIndex, int iElemLevel)
        {
            if (iElemIndex < 0)
            {
                iElemIndex = (Array.IndexOf(this.elements, null) > 0) ? Array.IndexOf(this.elements, null) - 1 : 0;
            }
            if (iElemLevel < 0)
            {
                iElemLevel = this.elements[iElemIndex - 1].level;
            }
            XMLElement Elem      = null;
            int        iAddIndex = iElemIndex;

            if (iElemIndex > 0 && iElemLevel > 0)
            {
                Elem = new XMLElement(strElement, strAttributes, arrAttributes, strText, iElemLevel + 1, this);
            }
            else
            {
                Elem = new XMLElement(strElement, strAttributes, arrAttributes, strText, 1, this);
            }
            this.elements = XMLUtilities.Add(this.elements, iAddIndex, Elem);
            for (int i = iAddIndex; i < Array.IndexOf(this.elements, null); i++)
            {
                this.elements[i].index = i;
            }
        }
Esempio n. 2
0
 public void removeElement(int iElemIndex)   // todo: use iterator here to remove more than 1 level down
 {
     while (this.elements[iElemIndex].childElement(0) != null)
     {
         this.elements = XMLUtilities.Remove(this.elements, iElemIndex + 1);
     }
     this.elements = XMLUtilities.Remove(this.elements, iElemIndex);
     for (int i = iElemIndex; i < Array.IndexOf(this.elements, null); i++)
     {
         this.elements[i].index = i;
     }
 }
Esempio n. 3
0
 public void removeAttribute(string AttributeName, string Value)
 {
     if (Array.IndexOf(this.attributes, null) == 0)
     {
         this.parseAttributes();
     }
     if (Array.IndexOf(this.attributes, null) != 0)
     {
         for (int i = 0; i < Array.IndexOf(this.attributes, null); i++)
         {
             if (this.attributes[i, 0] == AttributeName)
             {
                 this.attributes = XMLUtilities.Remove(this.attributes, i);
                 return;
             }
         }
     }
 }
Esempio n. 4
0
        public int addElementAt(string strElement, string[,] arrAttributes, string strAttributes, string strText, int iElemIndex, int iElemLevel)
        {
            if (iElemIndex < 0)
            {
                iElemIndex = (Array.IndexOf(this.elements, null) > 0) ? Array.IndexOf(this.elements, null) - 1 : 0;
            }
            if (iElemLevel < 0)
            {
                iElemLevel = this.elements[iElemIndex - 1].level;
            }
            XMLElement Elem;
            int        iAddIndex = iElemIndex;

            if (iElemIndex > 0)
            {
                for (int i = iElemIndex; i < Array.IndexOf(this.elements, null); i++)
                {
                    Console.WriteLine(this.elements[i].level + " > " + (iElemLevel + 1));
                    if (this.elements[i].level > iElemLevel + 1)
                    {
                        iAddIndex++;
                    }
                    else if (this.elements[i].level <= this.elements[iElemIndex].level)
                    {
                        break;
                    }
                }
                Elem = new XMLBuilder.XMLElement(strElement, strAttributes, arrAttributes, strText, iElemLevel + 1, this);
            }
            else
            {
                Elem = new XMLBuilder.XMLElement(strElement, strAttributes, arrAttributes, strText, 1, this);
            }
            this.elements = XMLUtilities.Add(this.elements, iAddIndex, Elem);
            for (int i = iAddIndex; i < Array.IndexOf(this.elements, null); i++)
            {
                this.elements[i].index = i;
            }
            return(iAddIndex);
        }
Esempio n. 5
0
        public string generateXML(bool bXMLTag)
        {
            string strXML = "";

            string[] arrXML = new string[512];
            int      lastelem;

            if (bXMLTag)
            {
                strXML += "<?xml version=\"1.0\"?>\n\n";
            }
            for (int i = 0; i < Array.IndexOf(this.elements, null); i++)
            {
                strXML += XMLUtilities.RepeatChar("\t", this.elements[i].level - 1);
                strXML += "<" + this.element(i).name;         // open tag
                if (this.element(i).attributes != null && this.element(i).attributes.GetLength(0) != 0)
                {
                    for (int j = 0; j < this.element(i).attributes.GetLength(0) && this.element(i).attributes[j, 0] != null; j++)           // set attributes
                    //???if (this.element(i).attributes[j]) {
                    {
                        strXML += ' ' + this.element(i).attributes[j, 0] + "=\"" + this.element(i).attributes[j, 1] + '"';
                        //}
                    }
                }                                                                                              //??? else strXML += this.element(i).attributeString.replace(/[\/>]$/gi, "");
                if (((this.elements[i + 1] != null && this.elements[i + 1].level <= this.elements[i].level) || // next element is a lower or equal to
                     (this.elements[i + 1] == null && this.elements[i - 1] != null)) &&     // no next element, previous element
                    this.element(i).text == "")
                {
                    strXML += "/";
                }
                strXML += ">";
                if (this.element(i).text != "")
                {
                    strXML += this.element(i).text;
                }
                else
                {
                    strXML += "\n";
                }
                if (((this.elements[i + 1] != null && this.elements[i + 1].level <= this.elements[i].level) ||     // next element is a lower or equal to
                     (this.elements[i + 1] == null && this.elements[i - 1] != null)) &&     // no next element, previous element
                    this.element(i).text != "")
                {
                    strXML += "</" + this.element(i).name + ">\n";
                }
                if (this.elements[i + 1] == null)
                {
                    lastelem = i;
                    for (int j = i; j > -1; j--)
                    {
                        if (this.elements[j].level >= this.elements[i].level)
                        {
                            continue;
                        }
                        else
                        {
                            if (this.elements[j].level < this.elements[lastelem].level)
                            {
                                strXML  += XMLUtilities.RepeatChar("\t", this.elements[j].level - 1) + "</" + this.element(j).name + ">\n";
                                lastelem = j;
                            }
                        }
                    }
                }
                else
                {
                    if (this.elements[i + 1].level < this.elements[i].level)
                    {
                        lastelem = i;
                        for (int j = i; this.elements[j].level >= this.elements[i + 1].level; j--)
                        {
                            if (this.elements[i] != null && this.elements[j] != null && this.elements[j].level < this.elements[i].level && this.elements[j].level < this.elements[lastelem].level)
                            {
                                strXML  += XMLUtilities.RepeatChar("\t", this.elements[j].level - 1) + "</" + this.element(j).name + ">\n";
                                lastelem = j;
                            }
                        }
                    }
                }
                if (strXML.Length > 1000)
                {
                    arrXML[Array.IndexOf(arrXML, null)] = strXML;
                    strXML = "";
                }
            }
            arrXML[Array.IndexOf(arrXML, null)] = strXML;
            return(string.Join("", arrXML));
        }