Esempio n. 1
0
 static int Pop(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         XMLNodeList obj = (XMLNodeList)ToLua.CheckObject(L, 1, typeof(XMLNodeList));
         XMLNode     o   = obj.Pop();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 2
0
    public static XMLNode Parse(string content)
    {
        if (string.IsNullOrEmpty(content))
        {
            return(null);
        }
        var rootNode = new XMLNode();

        //trim the situation: <br/>
        content           = content.Replace("/>", " />");
        rootNode["_text"] = "";

        string nodeContents = "";

        bool   inElement             = false;
        bool   collectNodeName       = false;
        bool   collectAttributeName  = false;
        bool   collectAttributeValue = false;
        bool   quoted    = false;
        string attName   = "";
        string attValue  = "";
        string nodeName  = "";
        string textValue = "";

        bool inMetaTag = false;
        bool inComment = false;
        bool inDoctype = false;
        bool inCDATA   = false;

        XMLNodeList parents = new XMLNodeList();

        XMLNode currentNode = rootNode;

        for (var i = 0; i < content.Length; i++)
        {
            char c = content[i];
            char cn;
            char cnn;
            char cp;
            cn = cnn = cp = '\0';
            if ((i + 1) < content.Length)
            {
                cn = content[i + 1];
            }
            if ((i + 2) < content.Length)
            {
                cnn = content[i + 2];
            }
            if (i > 0)
            {
                cp = content[i - 1];
            }

            if (inMetaTag)
            {
                if (c == QMARK && cn == GT)
                {
                    inMetaTag = false;
                    i++;
                }
                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == QMARK)
                {
                    inMetaTag = true;
                    continue;
                }
            }
            if (inDoctype)
            {
                if (cn == GT)
                {
                    inDoctype = false;
                    i++;
                }
                continue;
            }
            else if (inComment)
            {
                if (cp == DASH && c == DASH && cn == GT)
                {
                    inComment = false;
                    i++;
                }
                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == EXCLAMATION)
                {
                    if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                    {
                        inCDATA = true;
                        i      += 8;
                    }
                    else if (content.Length > i + 9 && content.Substring(i, 9) == "<!DOCTYPE")
                    {
                        inDoctype = true;
                        i        += 8;
                    }
                    else if (content.Length > i + 2 && content.Substring(i, 4) == "<!--")
                    {
                        inComment = true;
                        i        += 3;
                    }
                    continue;
                }
            }

            if (inCDATA)
            {
                if (c == SQR && cn == SQR && cnn == GT)
                {
                    inCDATA = false;
                    i      += 2;
                    continue;
                }
                textValue += c;
                continue;
            }

            if (inElement)
            {
                if (collectNodeName)
                {
                    if (c == SPACE)
                    {
                        collectNodeName = false;
                    }
                    else if (c == GT)
                    {
                        collectNodeName = false;
                        inElement       = false;
                    }

                    if (!collectNodeName && nodeName.Length > 0)
                    {
                        // close tag
                        if (nodeName[0] == SLASH)
                        {
                            // close tag
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }

                            textValue   = "";
                            nodeName    = "";
                            currentNode = parents.Pop();
                        }
                        else
                        {
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }
                            textValue = "";
                            XMLNode newNode = new XMLNode();
                            newNode["_text"] = "";

                            newNode["_name"] = nodeName;

                            if (currentNode[nodeName] == null)
                            {
                                currentNode[nodeName] = new XMLNodeList();
                            }
                            XMLNodeList a = currentNode[nodeName] as XMLNodeList;
                            a.Push(newNode);
                            parents.Push(currentNode);
                            currentNode = newNode;
                            nodeName    = "";
                        }
                    }
                    else
                    {
                        nodeName += c;
                    }
                }
                else
                {
                    if (!quoted && c == SLASH && cn == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;
                        if (!string.IsNullOrEmpty(attName))
                        {
                            if (!string.IsNullOrEmpty(attValue))
                            {
                                currentNode["@" + attName] = attValue;
                            }
                            else
                            {
                                currentNode["@" + attName] = true;
                            }
                        }

                        i++;
                        currentNode = parents.Pop();
                        attName     = "";
                        attValue    = "";
                    }
                    else if (!quoted && c == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;
                        if (!string.IsNullOrEmpty(attName))
                        {
                            currentNode["@" + attName] = attValue;
                        }

                        attName  = "";
                        attValue = "";
                    }
                    else
                    {
                        if (collectAttributeName)
                        {
                            if (c == SPACE || c == EQUALS)
                            {
                                collectAttributeName  = false;
                                collectAttributeValue = true;
                            }
                            else
                            {
                                attName += c;
                            }
                        }
                        else if (collectAttributeValue)
                        {
                            if (c == QUOTE)
                            {
                                if (quoted)
                                {
                                    collectAttributeValue      = false;
                                    currentNode["@" + attName] = attValue;
                                    attValue = "";
                                    attName  = "";
                                    quoted   = false;
                                }
                                else
                                {
                                    quoted = true;
                                }
                            }
                            else
                            {
                                if (quoted)
                                {
                                    attValue += c;
                                }
                                else
                                {
                                    if (c == SPACE)
                                    {
                                        collectAttributeValue      = false;
                                        currentNode["@" + attName] = attValue;
                                        attValue = "";
                                        attName  = "";
                                    }
                                }
                            }
                        }
                        else if (c == SPACE)
                        {
                        }
                        else
                        {
                            collectAttributeName = true;
                            attName  = "" + c;
                            attValue = "";
                            quoted   = false;
                        }
                    }
                }
            }
            else
            {
                if (c == LT)
                {
                    inElement       = true;
                    collectNodeName = true;
                }
                else
                {
                    textValue += c;
                }
            }
        }
        return(rootNode);
    }
Esempio n. 3
0
        public XMLNode Parse(string content)
        {
            XMLNode rootNode = new XMLNode();

            rootNode["_text"] = "";

            string nodeContents = "";

            bool   inElement             = false;
            bool   collectNodeName       = false;
            bool   collectAttributeName  = false;
            bool   collectAttributeValue = false;
            bool   quoted    = false;
            string attName   = "";
            string attValue  = "";
            string nodeName  = "";
            string textValue = "";

            bool inMetaTag = false;
            bool inComment = false;
            bool inCDATA   = false;

            XMLNodeList parents = new XMLNodeList();

            XMLNode currentNode = rootNode;

            for (int i = 0; i < content.Length; i++)
            {
                char c   = content[i];
                char cn  = '~';    // unused char  
                char cnn = '~';    // unused char  
                char cp  = '~';    // unused char  

                if ((i + 1) < content.Length)
                {
                    cn = content[i + 1];
                }
                if ((i + 2) < content.Length)
                {
                    cnn = content[i + 2];
                }
                if (i > 0)
                {
                    cp = content[i - 1];
                }

                if (inMetaTag)
                {
                    if (c == QMARK && cn == GT)
                    {
                        inMetaTag = false;
                        i++;
                    }

                    continue;
                }
                else
                {
                    if (!quoted && c == LT && cn == QMARK)
                    {
                        inMetaTag = true;
                        continue;
                    }
                }

                if (inComment)
                {
                    if (cp == DASH && c == DASH && cn == GT)
                    {
                        inComment = false;
                        i++;
                    }

                    continue;
                }
                else
                {
                    if (!quoted && c == LT && cn == EXCLAMATION)
                    {
                        if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                        {
                            inCDATA = true;
                            i      += 8;
                        }
                        else
                        {
                            inComment = true;
                        }

                        continue;
                    }
                }

                if (inCDATA)
                {
                    if (c == SQR && cn == SQR && cnn == GT)
                    {
                        inCDATA = false;
                        i      += 2;
                        continue;
                    }

                    textValue += c;
                    continue;
                }


                if (inElement)
                {
                    if (collectNodeName)
                    {
                        if (c == SPACE)
                        {
                            collectNodeName = false;
                        }
                        else if (c == GT)
                        {
                            collectNodeName = false;
                            inElement       = false;
                        }



                        if (!collectNodeName && nodeName.Length > 0)
                        {
                            if (nodeName[0] == SLASH)
                            {
                                // close tag  
                                if (textValue.Length > 0)
                                {
                                    currentNode["_text"] += textValue;
                                }

                                textValue   = "";
                                nodeName    = "";
                                currentNode = parents.Pop();
                            }
                            else
                            {
                                if (textValue.Length > 0)
                                {
                                    currentNode["_text"] += textValue;
                                }

                                textValue = "";
                                XMLNode newNode = new XMLNode();
                                newNode["_text"] = "";
                                newNode["_name"] = nodeName;

                                if (currentNode[nodeName] == null)
                                {
                                    currentNode[nodeName] = new XMLNodeList();
                                    if (currentNode["_types"] == null)
                                    {
                                        currentNode["_types"] = nodeName;
                                    }
                                    else
                                    {
                                        currentNode["_types"] = currentNode["_types"] + "#" + nodeName;
                                    }
                                }

                                XMLNodeList a = (XMLNodeList)currentNode[nodeName];
                                a.Push(newNode);
                                parents.Push(currentNode);
                                currentNode = newNode;
                                nodeName    = "";
                            }
                        }
                        else
                        {
                            nodeName += c;
                        }
                    }
                    else
                    {
                        if (!quoted && c == SLASH && cn == GT)
                        {
                            inElement             = false;
                            collectAttributeName  = false;
                            collectAttributeValue = false;
                            if (attName.Length > 0)
                            {
                                if (attValue.Length > 0)
                                {
                                    currentNode["@" + attName] = attValue;
                                }
                                else
                                {
                                    currentNode["@" + attName] = true;
                                }
                            }

                            i++;
                            currentNode = parents.Pop();
                            attName     = "";
                            attValue    = "";
                        }
                        else if (!quoted && c == GT)
                        {
                            inElement             = false;
                            collectAttributeName  = false;
                            collectAttributeValue = false;
                            if (attName.Length > 0)
                            {
                                currentNode["@" + attName] = attValue;
                            }

                            attName  = "";
                            attValue = "";
                        }
                        else
                        {
                            if (collectAttributeName)
                            {
                                if (c == SPACE || c == EQUALS)
                                {
                                    collectAttributeName  = false;
                                    collectAttributeValue = true;
                                }
                                else
                                {
                                    attName += c;
                                }
                            }
                            else if (collectAttributeValue)
                            {
                                if (c == QUOTE || c == QUOTE2)
                                {
                                    if (quoted)
                                    {
                                        collectAttributeValue      = false;
                                        currentNode["@" + attName] = attValue;
                                        attValue = "";
                                        attName  = "";
                                        quoted   = false;
                                    }
                                    else
                                    {
                                        quoted = true;
                                    }
                                }
                                else
                                {
                                    if (quoted)
                                    {
                                        attValue += c;
                                    }
                                    else
                                    {
                                        if (c == SPACE)
                                        {
                                            collectAttributeValue      = false;
                                            currentNode["@" + attName] = attValue;
                                            attValue = "";
                                            attName  = "";
                                        }
                                    }
                                }
                            }
                            else if (c == SPACE)
                            {
                            }
                            else
                            {
                                collectAttributeName = true;
                                attName  = "" + c;
                                attValue = "";
                                quoted   = false;
                            }
                        }
                    }
                }
                else
                {
                    if (c == LT)
                    {
                        inElement       = true;
                        collectNodeName = true;
                    }
                    else
                    {
                        textValue += c;
                    }
                }
            }

            return(rootNode);
        }
Esempio n. 4
0
    public static XMLNode Parse(string content)
    {
        // Set up variables
        bool   inMetaTag             = false;
        bool   inComment             = false;
        bool   inCDATA               = false;
        bool   inElement             = false;
        bool   collectNodeName       = false;
        bool   collectAttributeName  = false;
        bool   collectAttributeValue = false;
        bool   quoted    = false;
        string attName   = "";
        string attValue  = "";
        string nodeName  = "";
        string textValue = "";
        //string nodeContents = "";

        XMLNodeList parents = new XMLNodeList();

        XMLNode rootNode = new XMLNode();

        rootNode["_text"] = "";

        XMLNode currentNode = rootNode;

        // Process Input
        for (int i = 0; i < content.Length; i++)
        {
            // Store current and nearby characters
            char c, cn, cnn, cp;
            cn = cnn = cp = '\x00';
            c  = content[i];
            if ((i + 1) < content.Length)
            {
                cn = content[i + 1];
            }
            if ((i + 2) < content.Length)
            {
                cnn = content[i + 2];
            }
            if (i > 0)
            {
                cp = content[i - 1];
            }


            // Process Meta Tag information
            if (inMetaTag)
            {
                if (c == QMARK && cn == GT) // End of Meta Tag
                {
                    inMetaTag = false;
                    i++;
                }
                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == QMARK) // Start of Meta Tag
                {
                    inMetaTag = true;
                    continue;
                }
            }


            // Process Comment information
            if (inComment)
            {
                if (cp == DASH && c == DASH && cn == GT) // End of comment
                {
                    inComment = false;
                    i++;
                }
                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == EXCLAMATION) // Start of comment or CDATA
                {
                    if (content.Length > (i + 9) && content.Substring(i, 9) == "<![CDATA[")
                    {
                        inCDATA = true;
                        i      += 8;
                    }
                    else
                    {
                        inComment = true;
                    }
                    continue;
                }
            }


            // Process CDATA information
            if (inCDATA)
            {
                if (c == SQR && cn == SQR && cnn == GT)
                {
                    inCDATA = false;
                    i      += 2;
                    continue;
                }
                textValue += c;
                continue;
            }


            // Process Elements
            if (inElement)
            {
                if (collectNodeName)
                {
                    if (c == SPACE)
                    {
                        collectNodeName = false;
                    }
                    else if (c == GT)
                    {
                        collectNodeName = false;
                        inElement       = false;
                    }


                    if (!collectNodeName && nodeName.Length > 0)
                    {
                        if (nodeName[0] == SLASH)
                        {
                            // close tag
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }

                            textValue   = "";
                            nodeName    = "";
                            currentNode = parents.Pop();
                        }
                        else
                        {
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }
                            textValue = "";
                            XMLNode newNode = new XMLNode();
                            newNode["_text"] = "";
                            newNode["_name"] = nodeName;

                            if (!currentNode.ContainsKey(nodeName))
                            {
                                currentNode[nodeName] = new XMLNodeList();
                            }
                            XMLNodeList a = currentNode[nodeName] as XMLNodeList;
                            a.Push(newNode);
                            parents.Push(currentNode);
                            currentNode = newNode;
                            nodeName    = "";
                        }
                    }
                    else
                    {
                        nodeName += c;
                    }
                }
                else
                {
                    if (!quoted && c == SLASH && cn == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;
                        if (attName != "")
                        {
                            if (attValue != "")
                            {
                                currentNode["@" + attName] = attValue;
                            }
                            else
                            {
                                currentNode["@" + attName] = true;
                            }
                        }

                        i++;
                        currentNode = parents.Pop();
                        attName     = "";
                        attValue    = "";
                    }
                    else if (!quoted && c == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;
                        if (attName != "")
                        {
                            currentNode["@" + attName] = attValue;
                        }

                        attName  = "";
                        attValue = "";
                    }
                    else
                    {
                        if (collectAttributeName)
                        {
                            if (c == SPACE || c == EQUALS)
                            {
                                collectAttributeName  = false;
                                collectAttributeValue = true;
                            }
                            else
                            {
                                attName += c;
                            }
                        }
                        else if (collectAttributeValue)
                        {
                            if (c == QUOTE)
                            {
                                if (quoted)
                                {
                                    collectAttributeValue      = false;
                                    currentNode["@" + attName] = attValue;
                                    attValue = "";
                                    attName  = "";
                                    quoted   = false;
                                }
                                else
                                {
                                    quoted = true;
                                }
                            }
                            else
                            {
                                if (quoted)
                                {
                                    attValue += c;
                                }
                                else
                                {
                                    if (c == SPACE)
                                    {
                                        collectAttributeValue      = false;
                                        currentNode["@" + attName] = attValue;
                                        attValue = "";
                                        attName  = "";
                                    }
                                }
                            }
                        }
                        else if (c == SPACE)
                        {
                        }
                        else
                        {
                            collectAttributeName = true;
                            attName  = "" + c;
                            attValue = "";
                            quoted   = false;
                        }
                    }
                }
            }
            else
            {
                if (c == LT) // Start of new element
                {
                    inElement       = true;
                    collectNodeName = true;
                }
                else
                {
                    textValue += c; // text between elements
                }
            }
        }

        return(rootNode);
    }
    public XMLNode Parse(string content)
    {
        XMLNode rootNode = new XMLNode();
        rootNode["_text"] = "";

        //string nodeContents = "";

        bool inElement = false;
        bool collectNodeName = false;
        bool collectAttributeName = false;
        bool collectAttributeValue = false;
        bool quoted = false;
        string attName = "";
        string attValue = "";
        string nodeName = "";
        string textValue = "";

        bool inMetaTag = false;
        bool inComment = false;
        bool inCDATA = false;

        XMLNodeList parents = new XMLNodeList();

        XMLNode currentNode = rootNode;

        for (int i = 0; i < content.Length; i++)
        {
            char c = content[i];
            char cn = '~';  // unused char
            char cnn = '~'; // unused char
            char cp = '~';  // unused char

            if ((i + 1) < content.Length) cn = content[i + 1];
            if ((i + 2) < content.Length) cnn = content[i + 2];
            if (i > 0) cp = content[i - 1];

            if (inMetaTag)
            {
                if (c == QMARK && cn == GT)
                {
                    inMetaTag = false;
                    i++;
                }

                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == QMARK)
                {
                    inMetaTag = true;
                    continue;
                }
            }

            if (inComment)
            {
                if (cp == DASH && c == DASH && cn == GT)
                {
                    inComment = false;
                    i++;
                }

                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == EXCLAMATION)
                {

                    if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                    {
                        inCDATA = true;
                        i += 8;
                    }
                    else
                    {
                        inComment = true;
                    }

                    continue;
                }
            }

            if (inCDATA)
            {
                if (c == SQR && cn == SQR && cnn == GT)
                {
                    inCDATA = false;
                    i += 2;
                    continue;
                }

                textValue += c;
                continue;
            }

            if (inElement)
            {
                if (collectNodeName)
                {
                    if (c == SPACE)
                    {
                        collectNodeName = false;
                    }
                    else if (c == GT)
                    {
                        collectNodeName = false;
                        inElement=false;
                    }

                    if (!collectNodeName && nodeName.Length > 0)
                    {
                        if (nodeName[0] == SLASH)
                        {
                            // close tag
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }

                            textValue = "";
                            nodeName = "";
                            currentNode = parents.Pop();
                        }
                        else
                        {
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }

                            textValue = "";
                            XMLNode newNode = new XMLNode();
                            newNode["_text"] = "";
                            newNode["_name"] = nodeName;

                            if (currentNode[nodeName] == null)
                            {
                                currentNode[nodeName] = new XMLNodeList();
                            }

                            XMLNodeList a = (XMLNodeList)currentNode[nodeName];
                            a.Push(newNode);
                            parents.Push(currentNode);
                            currentNode=newNode;
                            nodeName="";
                        }
                    }
                    else
                    {
                        nodeName += c;
                    }
                }
                else
                {
                    if(!quoted && c == SLASH && cn == GT)
                    {
                        inElement = false;
                        collectAttributeName = false;
                        collectAttributeValue = false;
                        if (attName.Length > 0)
                        {
                            if (attValue.Length > 0)
                            {
                                currentNode["@" + attName] = attValue;
                            }
                            else
                            {
                                currentNode["@" + attName] = true;
                            }
                        }

                        i++;
                        currentNode = parents.Pop();
                        attName = "";
                        attValue = "";
                    }
                    else if (!quoted && c == GT)
                    {
                        inElement = false;
                        collectAttributeName = false;
                        collectAttributeValue = false;
                        if (attName.Length > 0)
                        {
                            currentNode["@" + attName] = attValue;
                        }

                        attName = "";
                        attValue = "";
                    }
                    else
                    {
                        if (collectAttributeName)
                        {
                            if (c == SPACE || c == EQUALS)
                            {
                                collectAttributeName = false;
                                collectAttributeValue = true;
                            }
                            else
                            {
                                attName += c;
                            }
                        }
                        else if (collectAttributeValue)
                        {
                            if (c == QUOTE || c == QUOTE2)
                            {
                                if (quoted)
                                {
                                    collectAttributeValue = false;
                                    currentNode["@" + attName] = attValue;
                                    attValue = "";
                                    attName = "";
                                    quoted = false;
                                }
                                else
                                {
                                    quoted = true;
                                }
                            }
                            else
                            {
                                if (quoted)
                                {
                                    attValue += c;
                                }
                                else
                                {
                                    if (c == SPACE)
                                    {
                                        collectAttributeValue = false;
                                        currentNode["@" + attName] = attValue;
                                        attValue = "";
                                        attName = "";
                                    }
                                }
                            }
                        }
                        else if (c == SPACE)
                        {

                        }
                        else
                        {
                            collectAttributeName = true;
                            attName = "" + c;
                            attValue = "";
                            quoted = false;
                        }
                    }
                }
            }
            else
            {
                if (c == LT)
                {
                    inElement = true;
                    collectNodeName = true;
                }
                else
                {
                    textValue += c;
                }
            }
        }

        return rootNode;
    }
Esempio n. 6
0
    public XMLNode Parse(string content)
    {
        XMLNode xMLNode = new XMLNode();

        xMLNode["_text"] = new StringBuilder();
        bool          flag           = false;
        bool          flag2          = false;
        bool          flag3          = false;
        bool          flag4          = false;
        bool          flag5          = false;
        StringBuilder stringBuilder  = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        bool          flag6          = false;
        bool          flag7          = false;
        bool          flag8          = false;
        XMLNodeList   xMLNodeList    = new XMLNodeList();
        XMLNode       xMLNode2       = xMLNode;

        for (int i = 0; i < content.Length; i++)
        {
            char c  = content[i];
            char c2 = '~';
            char c3 = '~';
            char c4 = '~';
            if (i + 1 < content.Length)
            {
                c2 = content[i + 1];
            }
            if (i + 2 < content.Length)
            {
                c3 = content[i + 2];
            }
            if (i > 0)
            {
                c4 = content[i - 1];
            }
            if (flag6)
            {
                if (c == this.QMARK && c2 == this.GT)
                {
                    flag6 = false;
                    i++;
                }
            }
            else if (!flag5 && c == this.LT && c2 == this.QMARK)
            {
                flag6 = true;
            }
            else if (flag7)
            {
                if (c4 == this.DASH && c == this.DASH && c2 == this.GT)
                {
                    flag7 = false;
                    i++;
                }
            }
            else if (!flag5 && c == this.LT && c2 == this.EXCLAMATION)
            {
                if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                {
                    flag8 = true;
                    i    += 8;
                }
                else
                {
                    flag7 = true;
                }
            }
            else if (flag8)
            {
                if (c == this.SQR && c2 == this.SQR && c3 == this.GT)
                {
                    flag8 = false;
                    i    += 2;
                }
                else
                {
                    stringBuilder4.Append(c);
                }
            }
            else if (flag)
            {
                if (flag2)
                {
                    if (c == this.SPACE)
                    {
                        flag2 = false;
                    }
                    else if (c == this.GT)
                    {
                        flag2 = false;
                        flag  = false;
                    }
                    if (!flag2 && stringBuilder.Length > 0)
                    {
                        if (stringBuilder[0] == this.SLASH)
                        {
                            if (stringBuilder4.Length > 0)
                            {
                            }
                            stringBuilder4.Remove(0, stringBuilder4.Length);
                            stringBuilder.Remove(0, stringBuilder.Length);
                            xMLNode2 = xMLNodeList.Pop();
                        }
                        else
                        {
                            if (stringBuilder4.Length > 0)
                            {
                            }
                            stringBuilder4.Remove(0, stringBuilder4.Length);
                            string  text     = stringBuilder.ToString();
                            XMLNode xMLNode3 = new XMLNode();
                            xMLNode3["_text"] = new StringBuilder();
                            xMLNode3["_name"] = text;
                            if (xMLNode2[text] == null)
                            {
                                xMLNode2[text] = new XMLNodeList();
                            }
                            XMLNodeList xMLNodeList2 = (XMLNodeList)xMLNode2[text];
                            xMLNodeList2.Push(xMLNode3);
                            xMLNodeList.Push(xMLNode2);
                            xMLNode2 = xMLNode3;
                            stringBuilder.Remove(0, stringBuilder.Length);
                        }
                    }
                    else
                    {
                        stringBuilder.Append(c);
                    }
                }
                else if (!flag5 && c == this.SLASH && c2 == this.GT)
                {
                    flag  = false;
                    flag3 = false;
                    flag4 = false;
                    if (stringBuilder2.Length > 0)
                    {
                        if (stringBuilder3.Length > 0)
                        {
                            xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = stringBuilder3.ToString();
                        }
                        else
                        {
                            xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = true;
                        }
                    }
                    i++;
                    xMLNode2 = xMLNodeList.Pop();
                    stringBuilder2.Remove(0, stringBuilder2.Length);
                    stringBuilder3.Remove(0, stringBuilder3.Length);
                }
                else if (!flag5 && c == this.GT)
                {
                    flag  = false;
                    flag3 = false;
                    flag4 = false;
                    if (stringBuilder2.Length > 0)
                    {
                        xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = stringBuilder3.ToString();
                    }
                    stringBuilder2.Remove(0, stringBuilder2.Length);
                    stringBuilder3.Remove(0, stringBuilder3.Length);
                }
                else if (flag3)
                {
                    if (c == this.SPACE || c == this.EQUALS)
                    {
                        flag3 = false;
                        flag4 = true;
                    }
                    else
                    {
                        stringBuilder2.Append(c);
                    }
                }
                else if (flag4)
                {
                    if (c == this.QUOTE || c == this.QUOTE2)
                    {
                        if (flag5)
                        {
                            flag4 = false;
                            xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = stringBuilder3.ToString();
                            stringBuilder2.Remove(0, stringBuilder2.Length);
                            stringBuilder3.Remove(0, stringBuilder3.Length);
                            flag5 = false;
                        }
                        else
                        {
                            flag5 = true;
                        }
                    }
                    else if (flag5)
                    {
                        stringBuilder3.Append(c);
                    }
                    else if (c == this.SPACE)
                    {
                        flag4 = false;
                        xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = stringBuilder3.ToString();
                        stringBuilder2.Remove(0, stringBuilder2.Length);
                        stringBuilder3.Remove(0, stringBuilder3.Length);
                    }
                }
                else if (c != this.SPACE)
                {
                    flag3 = true;
                    stringBuilder2.Remove(0, stringBuilder2.Length).Append(c);
                    stringBuilder3.Remove(0, stringBuilder3.Length);
                    flag5 = false;
                }
            }
            else if (c == this.LT)
            {
                flag  = true;
                flag2 = true;
            }
            else
            {
                stringBuilder4.Append(c);
            }
        }
        return(xMLNode);
    }
Esempio n. 7
0
        public XMLNode Parse(string content)
        {
            XMLNode xMLNode = new XMLNode();

            xMLNode["_text"] = "";
            bool        flag        = false;
            bool        flag2       = false;
            bool        flag3       = false;
            bool        flag4       = false;
            bool        flag5       = false;
            string      text        = "";
            string      text2       = "";
            string      text3       = "";
            string      text4       = "";
            bool        flag6       = false;
            bool        flag7       = false;
            bool        flag8       = false;
            XMLNodeList xMLNodeList = new XMLNodeList();
            XMLNode     xMLNode2    = xMLNode;

            for (int i = 0; i < content.Length; i++)
            {
                char c  = content[i];
                char c2 = '~';
                char c3 = '~';
                char c4 = '~';
                if (i + 1 < content.Length)
                {
                    c2 = content[i + 1];
                }
                if (i + 2 < content.Length)
                {
                    c3 = content[i + 2];
                }
                if (i > 0)
                {
                    c4 = content[i - 1];
                }
                if (flag6)
                {
                    if (c == QMARK && c2 == GT)
                    {
                        flag6 = false;
                        i++;
                    }
                }
                else if (!flag5 && c == LT && c2 == QMARK)
                {
                    flag6 = true;
                }
                else if (flag7)
                {
                    if (c4 == DASH && c == DASH && c2 == GT)
                    {
                        flag7 = false;
                        i++;
                    }
                }
                else if (!flag5 && c == LT && c2 == EXCLAMATION)
                {
                    if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                    {
                        flag8 = true;
                        i    += 8;
                    }
                    else
                    {
                        flag7 = true;
                    }
                }
                else if (flag8)
                {
                    if (c == SQR && c2 == SQR && c3 == GT)
                    {
                        flag8 = false;
                        i    += 2;
                    }
                    else
                    {
                        text4 += c;
                    }
                }
                else if (flag)
                {
                    if (flag2)
                    {
                        if (c == SPACE)
                        {
                            flag2 = false;
                        }
                        else if (c == GT)
                        {
                            flag2 = false;
                            flag  = false;
                        }
                        if (!flag2 && text3.Length > 0)
                        {
                            if (text3[0] == SLASH)
                            {
                                if (text4.Length > 0)
                                {
                                    XMLNode xMLNode3;
                                    XMLNode xMLNode4 = (xMLNode3 = xMLNode2);
                                    object  obj      = xMLNode3["_text"];
                                    xMLNode4["_text"] = string.Concat(obj, text4);
                                }
                                text4    = "";
                                text3    = "";
                                xMLNode2 = xMLNodeList.Pop();
                                continue;
                            }
                            if (text4.Length > 0)
                            {
                                XMLNode xMLNode5;
                                XMLNode xMLNode6 = (xMLNode5 = xMLNode2);
                                object  obj      = xMLNode5["_text"];
                                xMLNode6["_text"] = string.Concat(obj, text4);
                            }
                            text4 = "";
                            XMLNode xMLNode7 = new XMLNode();
                            xMLNode7["_text"] = "";
                            xMLNode7["_name"] = text3;
                            if (xMLNode2[text3] == null)
                            {
                                xMLNode2[text3] = new XMLNodeList();
                            }
                            XMLNodeList xMLNodeList2 = (XMLNodeList)xMLNode2[text3];
                            xMLNodeList2.Push(xMLNode7);
                            xMLNodeList.Push(xMLNode2);
                            xMLNode2 = xMLNode7;
                            text3    = "";
                        }
                        else
                        {
                            text3 += c;
                        }
                    }
                    else if (!flag5 && c == SLASH && c2 == GT)
                    {
                        flag  = false;
                        flag3 = false;
                        flag4 = false;
                        if (text.Length > 0)
                        {
                            if (text2.Length > 0)
                            {
                                xMLNode2["@" + text] = text2;
                            }
                            else
                            {
                                xMLNode2["@" + text] = true;
                            }
                        }
                        i++;
                        xMLNode2 = xMLNodeList.Pop();
                        text     = "";
                        text2    = "";
                    }
                    else if (!flag5 && c == GT)
                    {
                        flag  = false;
                        flag3 = false;
                        flag4 = false;
                        if (text.Length > 0)
                        {
                            xMLNode2["@" + text] = text2;
                        }
                        text  = "";
                        text2 = "";
                    }
                    else if (flag3)
                    {
                        if (c == SPACE || c == EQUALS)
                        {
                            flag3 = false;
                            flag4 = true;
                        }
                        else
                        {
                            text += c;
                        }
                    }
                    else if (flag4)
                    {
                        if (c == QUOTE || c == QUOTE2)
                        {
                            if (flag5)
                            {
                                flag4 = false;
                                xMLNode2["@" + text] = text2;
                                text2 = "";
                                text  = "";
                                flag5 = false;
                            }
                            else
                            {
                                flag5 = true;
                            }
                        }
                        else if (flag5)
                        {
                            text2 += c;
                        }
                        else if (c == SPACE)
                        {
                            flag4 = false;
                            xMLNode2["@" + text] = text2;
                            text2 = "";
                            text  = "";
                        }
                    }
                    else if (c != SPACE)
                    {
                        flag3 = true;
                        text  = "" + c;
                        text2 = "";
                        flag5 = false;
                    }
                }
                else if (c == LT)
                {
                    flag  = true;
                    flag2 = true;
                }
                else
                {
                    text4 += c;
                }
            }
            return(xMLNode);
        }
Esempio n. 8
0
    public XMLNode Parse(string content, int iOffset = 0)
    {
        XMLNode rootNode = new XMLNode();

        //rootNode["_text"] = System.String.Empty;
        rootNode["_text"] = new StringBuilder();

        bool inElement             = false;
        bool collectNodeName       = false;
        bool collectAttributeName  = false;
        bool collectAttributeValue = false;
        bool quoted = false;

        StringBuilder nodeNameStrBuilder  = new StringBuilder();
        StringBuilder attNameStrBuilder   = new StringBuilder();
        StringBuilder attValueStrBuilder  = new StringBuilder();
        StringBuilder textValueStrBuilder = new StringBuilder();

        bool inMetaTag = false;
        bool inComment = false;
        bool inCDATA   = false;

        XMLNodeList parents = new XMLNodeList();

        XMLNode currentNode = rootNode;

        for (int i = iOffset; i < content.Length; i++)
        {
            char c   = content[i];
            char cn  = '~'; // unused char
            char cnn = '~'; // unused char
            char cp  = '~'; // unused char

            if ((i + 1) < content.Length)
            {
                cn = content[i + 1];
            }
            if ((i + 2) < content.Length)
            {
                cnn = content[i + 2];
            }
            if (i > 0)
            {
                cp = content[i - 1];
            }

            if (inMetaTag)
            {
                if (c == QMARK && cn == GT)
                {
                    inMetaTag = false;
                    i++;
                }

                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == QMARK)
                {
                    inMetaTag = true;
                    continue;
                }
            }

            if (inComment)
            {
                if (cp == DASH && c == DASH && cn == GT)
                {
                    inComment = false;
                    i++;
                }

                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == EXCLAMATION)
                {
                    if ((content.Length > i + 9) && string.Compare("< ![CDATA[", 0, content, i, 9) == 0)
                    {
                        inCDATA = true;
                        i      += 8;
                    }
                    else
                    {
                        inComment = true;
                    }

                    continue;
                }
            }

            if (inCDATA)
            {
                if (c == SQR && cn == SQR && cnn == GT)
                {
                    inCDATA = false;
                    i      += 2;
                    continue;
                }

                textValueStrBuilder.Append(c);
                continue;
            }

            if (inElement)
            {
                if (collectNodeName)
                {
                    if (c == SPACE)
                    {
                        collectNodeName = false;
                    }
                    else if (c == GT)
                    {
                        collectNodeName = false;
                        inElement       = false;
                    }

                    if (!collectNodeName && nodeNameStrBuilder.Length > 0)
                    {
                        if (nodeNameStrBuilder[0] == SLASH)
                        {
                            // close tag
                            if (textValueStrBuilder.Length > 0)
                            {
                                //currentNode["_text"] = textValueStrBuilder.ToString();
                                //currentNode["_text"] += textValueStrBuilder.ToString();
                                //(currentNode["_text"] as StringBuilder).Append( textValueStrBuilder.ToString() );
                            }

                            textValueStrBuilder.Remove(0, textValueStrBuilder.Length);
                            nodeNameStrBuilder.Remove(0, nodeNameStrBuilder.Length);
                            currentNode = parents.Pop();
                        }
                        else
                        {
                            if (textValueStrBuilder.Length > 0)
                            {
                                //currentNode["_text"] = textValueStrBuilder.ToString();
                                //currentNode["_text"] += textValueStrBuilder.ToString();
                                //(currentNode["_text"] as StringBuilder).Append( textValueStrBuilder.ToString() );
                            }

                            textValueStrBuilder.Remove(0, textValueStrBuilder.Length);
                            string  nodeNameString = nodeNameStrBuilder.ToString();
                            XMLNode newNode        = new XMLNode();
                            //newNode["_text"] = System.String.Empty;
                            newNode["_text"] = new StringBuilder();
                            newNode["_name"] = nodeNameString;

                            if (currentNode[nodeNameString] == null)
                            {
                                currentNode[nodeNameString] = new XMLNodeList();
                            }

                            XMLNodeList a = (XMLNodeList)currentNode[nodeNameString];
                            a.Push(newNode);
                            parents.Push(currentNode);
                            currentNode = newNode;
                            nodeNameStrBuilder.Remove(0, nodeNameStrBuilder.Length);
                        }
                    }
                    else
                    {
                        nodeNameStrBuilder.Append(c);
                    }
                }
                else
                {
                    if (!quoted && c == SLASH && cn == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;

                        if (attNameStrBuilder.Length > 0)
                        {
                            if (attValueStrBuilder.Length > 0)
                            {
                                currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = attValueStrBuilder.ToString();
                            }
                            else
                            {
                                currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = true;
                            }
                        }

                        i++;
                        currentNode = parents.Pop();
                        attNameStrBuilder.Remove(0, attNameStrBuilder.Length);
                        attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                    }
                    else if (!quoted && c == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;

                        if (attNameStrBuilder.Length > 0)
                        {
                            currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = attValueStrBuilder.ToString();
                        }

                        attNameStrBuilder.Remove(0, attNameStrBuilder.Length);
                        attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                    }
                    else
                    {
                        if (collectAttributeName)
                        {
                            if (c == SPACE || c == EQUALS)
                            {
                                collectAttributeName  = false;
                                collectAttributeValue = true;
                            }
                            else
                            {
                                attNameStrBuilder.Append(c);
                            }
                        }
                        else if (collectAttributeValue)
                        {
                            if (c == QUOTE || c == QUOTE2)
                            {
                                if (quoted)
                                {
                                    collectAttributeValue = false;
                                    currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = attValueStrBuilder.ToString();

                                    attNameStrBuilder.Remove(0, attNameStrBuilder.Length);
                                    attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                                    quoted = false;
                                }
                                else
                                {
                                    quoted = true;
                                }
                            }
                            else
                            {
                                if (quoted)
                                {
                                    attValueStrBuilder.Append(c);
                                }
                                else
                                {
                                    if (c == SPACE)
                                    {
                                        collectAttributeValue = false;
                                        currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = attValueStrBuilder.ToString();
                                        attNameStrBuilder.Remove(0, attNameStrBuilder.Length);
                                        attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                                    }
                                }
                            }
                        }
                        else if (c == SPACE)
                        {
                        }
                        else
                        {
                            collectAttributeName = true;

                            attNameStrBuilder.Remove(0, attNameStrBuilder.Length).Append(c);
                            attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                            quoted = false;
                        }
                    }
                }
            }
            else
            {
                if (c == LT)
                {
                    inElement       = true;
                    collectNodeName = true;
                }
                else
                {
                    textValueStrBuilder.Append(c);
                }
            }
        }

        return(rootNode);
    }