private void ParseTagAttributes(ParsedTag t, string input)
        {
            string tagname = ParseTagName(input);
            string temp = input.TrimStart('<');
            temp = temp.TrimEnd('>');
            temp = temp.TrimEnd('/');
            //Trim off tag name
            temp = temp.Substring(tagname.Length, temp.Length - (tagname.Length));
            temp = temp.Trim();

            bool isParsingAttribute = false;
            bool isParsingAttributeValue = false;

            TempAttr currentAttribute = null;

            // loop through all characters, splitting of attributes
            char[] characters = temp.ToCharArray();
            for (int i = 0; i < temp.Length; i++)
            {
                char current = temp[i];

                if (isParsingAttribute)
                {
                    if (isParsingAttributeValue)
                    {
                        // append the current character
                        currentAttribute.Value += current;

                        // check to see if we're done with the attribute
                        if (currentAttribute.Value.Length >= 2)
                        {
                            if (currentAttribute.Value.EndsWith("\""))
                            {
                                isParsingAttributeValue = false;
                                isParsingAttribute = false;

                                currentAttribute.Value = currentAttribute.Value.TrimStart('"');
                                currentAttribute.Value = currentAttribute.Value.TrimEnd('"');

                                // Add or overwrite value
                                t.SetSafeAttribute(currentAttribute.Name, currentAttribute.Value);

                                currentAttribute = null;
                            }
                        }
                    }
                    else
                    {
                        // we're not parsing the value yet so check for "="
                        if (current == '=')
                        {
                            // skip this charater but enable attribute value parsing;
                            isParsingAttributeValue = true;
                        }
                        else
                        {
                            currentAttribute.Name += current;
                        }
                    }
                }
                else
                {
                    // not parsing right now, check to see if we need to start
                    if (!char.IsWhiteSpace(current))
                    {
                        // not white space so let's start our attribute name
                        currentAttribute = new TempAttr(current.ToString(), "");
                        isParsingAttribute = true;
                    }

                }

            }
        }
示例#2
0
        private void ParseTagAttributes(ParsedTag t, string input)
        {
            string tagname = ParseTagName(input);
            string temp    = input.TrimStart('<');

            temp = temp.TrimEnd('>');
            temp = temp.TrimEnd('/');
            //Trim off tag name
            temp = temp.Substring(tagname.Length, temp.Length - (tagname.Length));
            temp = temp.Trim();

            bool isParsingAttribute      = false;
            bool isParsingAttributeValue = false;

            TempAttr currentAttribute = null;

            // loop through all characters, splitting of attributes
            char[] characters = temp.ToCharArray();
            for (int i = 0; i < temp.Length; i++)
            {
                char current = temp[i];

                if (isParsingAttribute)
                {
                    if (isParsingAttributeValue)
                    {
                        // append the current character
                        currentAttribute.Value += current;

                        // check to see if we're done with the attribute
                        if (currentAttribute.Value.Length >= 2)
                        {
                            if (currentAttribute.Value.EndsWith("\""))
                            {
                                isParsingAttributeValue = false;
                                isParsingAttribute      = false;

                                currentAttribute.Value = currentAttribute.Value.TrimStart('"');
                                currentAttribute.Value = currentAttribute.Value.TrimEnd('"');

                                // Add or overwrite value
                                t.SetSafeAttribute(currentAttribute.Name, currentAttribute.Value);

                                currentAttribute = null;
                            }
                        }
                    }
                    else
                    {
                        // we're not parsing the value yet so check for "="
                        if (current == '=')
                        {
                            // skip this charater but enable attribute value parsing;
                            isParsingAttributeValue = true;
                        }
                        else
                        {
                            currentAttribute.Name += current;
                        }
                    }
                }
                else
                {
                    // not parsing right now, check to see if we need to start
                    if (!char.IsWhiteSpace(current))
                    {
                        // not white space so let's start our attribute name
                        currentAttribute   = new TempAttr(current.ToString(), "");
                        isParsingAttribute = true;
                    }
                }
            }
        }