예제 #1
0
        public string getCData(AgentPath path)
        {
            string cData = "";

            // get us jump-started to the root element, putting us past any script noise typically in the beginning of the document;
            // note that if the root element is not the first of its type, then we can't just jump down like this

            int startOfBody = path.ElementIndex == 1 ? ResponseString.LastIndexOf("<" + path.ElementType) : 0;

            int index = path.positionOf(ResponseString, startOfBody);

            char[] docChars = ResponseString.ToCharArray();

            bool flag = true;

            while (flag)
            {
                while (docChars[index] != '<')
                {
                    cData += docChars[index++];
                }

                // skip past comments if there are any
                if (docChars[index + 1] == '!' && docChars[index + 2] == '-' && docChars[index + 3] == '-')
                {
                    while (!(docChars[index] == '>' && docChars[index - 1] == '-' && docChars[index - 2] == '-'))
                    {
                        index++;
                    }
                    index++;
                }
                else
                {
                    flag = false;
                }
            }
            return(cData);
        }
예제 #2
0
        public AgentPath CreateChild(string type, int index)
        {
            Next = new AgentPath(type, index);

            return(Next);
        }
예제 #3
0
        public string getValue(AgentPath path, string attribute)
        {
            // get us jump-started to the root element, putting us past any script noise typically in the beginning of the document;
            // note that if the root element is not the first of its type, then we can't just jump down like this
            int startOfBody = path.ElementIndex == 1 ? ResponseString.LastIndexOf("<" + path.ElementType) : 0;
            int index       = path.positionOf(ResponseString, startOfBody) - 2;       // go behind the ending tag

            char[] docChars = ResponseString.ToCharArray();

            // go backwards, and read off key/value pairs - if we reach the start tag, then the key wasn't found
            while (true)
            {
                // get data
                bool   inQuotes    = false;
                bool   foundEquals = false;
                string elmValue    = "";

                while (!foundEquals)
                {
                    if (docChars[index] == '\"')
                    {
                        inQuotes = !inQuotes;
                    }

                    else if (docChars[index] == '\'')
                    {
                        inQuotes = !inQuotes;
                    }

                    else if (docChars[index] == '=' && !inQuotes)
                    {
                        foundEquals = true;
                    }

                    else if (docChars[index] == '<' && !inQuotes)
                    {
                        throw new Exception("attribute " + attribute + " not found.");
                    }

                    else
                    {
                        elmValue = docChars[index] + elmValue;
                    }

                    index--;
                }

                while (docChars[index] == ' ')
                {
                    index--;
                }

                string key = "";

                while (docChars[index] != ' ')
                {
                    key = docChars[index--] + key;
                }

                key = key.ToLower();

                if (key.Equals(attribute))
                {
                    return(elmValue);
                }
            }
        }