Beispiel #1
0
        internal XMLAttribute AddAttribute(string n, string value_ren)
        {
            XMLAttribute attribute = new XMLAttribute(n, value_ren);

            attributes.Add(n, attribute);
            return(attribute);
        }
Beispiel #2
0
        private void NewElement(string context, XMLListener l, int index)
        {
            string o = "";
            int    i;
            string str1;

            if (context.EndsWith("/>"))
            {
                i    = 2;
                str1 = context.Substring(1, (context.Length - 2) - (1));
            }
            else if (context.StartsWith("</"))
            {
                i    = 1;
                str1 = context.Substring(2, (context.Length - 1) - (2));
            }
            else
            {
                i    = 0;
                str1 = context.Substring(1, (context.Length - 1) - (1));
            }
            try {
                if (str1.IndexOf(' ') < 0)
                {
                    o = str1;
                    switch (i)
                    {
                    case OPEN_TAG:
                        PushElement(new XMLElement(o), index, l);
                        break;

                    case CLOSE_TAG:
                        if (this.topElement.GetName().Equals(o))
                        {
                            PopElement(index, l);
                        }
                        else
                        {
                            throw new Exception("Expected close of '"
                                                + this.topElement.GetName() + "' instead of "
                                                + context);
                        }
                        break;

                    case OPEN_CLOSE_TAG:
                        PushElement(new XMLElement(o), index, l);
                        PopElement(index, l);
                        break;
                    }
                }
                else
                {
                    XMLElement el = null;
                    o = str1.Substring(0, (str1.IndexOf(' ')) - (0));
                    switch (i)
                    {
                    case OPEN_TAG:
                        el = new XMLElement(o);
                        PushElement(el, index, l);
                        break;

                    case CLOSE_TAG:
                        throw new Exception("Syntax Error: " + context);

                    case OPEN_CLOSE_TAG:
                        el = new XMLElement(o);
                        PushElement(el, index, l);
                        PopElement(index, l);
                        break;
                    }
                    string str2  = str1.Substring(str1.IndexOf(' ') + 1);
                    int    start = 0;
                    int    end   = 0;

                    StringBuilder sbr1 = new StringBuilder(128);
                    StringBuilder sbr2 = new StringBuilder(32);
                    for (int m = 0; m < str2.Length; m++)
                    {
                        switch ((int)str2[m])
                        {
                        case '"':

                            start = (start != 0) ? 0 : 1;
                            break;

                        case ' ':
                            if ((end == 1) && (start == 1))
                            {
                                sbr1.Append(str2[m]);
                            }
                            else if (sbr2.Length > 0)
                            {
                                string key       = sbr2.ToString();
                                string value_ren = sbr1.ToString();
                                if (key.Length > 0)
                                {
                                    XMLAttribute a = el.AddAttribute(key, value_ren);
                                    a.element = el;
                                    if (l != null)
                                    {
                                        l.AddAttribute(index, a);
                                    }
                                }
                                end = 0;
                                sbr1.Remove(0, sbr1.Length - (0));
                                sbr2.Remove(0, sbr2.Length - (0));
                            }
                            break;

                        case '=':

                            if (start == 0)
                            {
                                end = 1;
                            }
                            break;

                        case '!':
                        case '#':
                        case '$':
                        case '%':
                        case '&':
                        case '\'':
                        case '(':
                        case ')':
                        case '*':
                        case '+':
                        case ',':
                        case '-':
                        case '.':
                        case '/':
                        case '0':
                        case '1':
                        case '2':
                        case '3':
                        case '4':
                        case '5':
                        case '6':
                        case '7':
                        case '8':
                        case '9':
                        case ':':
                        case ';':
                        case '<':
                        default:
                            if (end != 0)
                            {
                                sbr1.Append(str2[m]);
                            }
                            else
                            {
                                sbr2.Append(str2[m]);
                            }
                            break;
                        }
                    }
                    if (sbr1.Length > 0)
                    {
                        string       key_0   = sbr2.ToString();
                        string       value_1 = sbr1.ToString();
                        XMLAttribute a_2     = el.AddAttribute(key_0, value_1);
                        a_2.element = el;
                        if (l != null)
                        {
                            l.AddAttribute(index, a_2);
                        }
                    }
                }
            } catch (Exception e) {
                throw new Exception("Cannot parse element '" + context
                                    + "' - (" + e + ")");
            }
        }
 public virtual void AddAttribute(int line, XMLAttribute a)
 {
     if (a != null)
     {
         XMLElement ele = a.GetElement();
         if (flag_source.ToUpper() == a.GetName().ToUpper())
         {
             _read._source = a.GetValue();
         }
         else if (flag_type.ToUpper() == a.GetName().ToUpper())
         {
             _read._classType = a.GetValue();
         }
         else if (ele != null)
         {
             _read._classType = ele.GetName();
         }
     }
 }
Beispiel #4
0
 internal XMLAttribute AddAttribute(string n, string value_ren)
 {
     XMLAttribute attribute = new XMLAttribute(n, value_ren);
     attributes.Add(n, attribute);
     return attribute;
 }
Beispiel #5
0
		public void Start_attr(XMLAttribute attr)  {
			Start_attr(attr.GetName(), attr.GetValue());
		}
Beispiel #6
0
 public void Start_attr(XMLAttribute attr)
 {
     Start_attr(attr.GetName(), attr.GetValue());
 }