예제 #1
0
        public static cbrType ParserCallback(BAFASCycleObject value, xpNodeType nodeType, string Name, string Attrs, string Xml)
        {
            BAFASCycleObject This = (BAFASCycleObject)value;

            if (string.Compare("Cycle", Name) == 0)
            {
                This.AttributeString = (Attrs);

                return(cbrType.cbr_OK);
            }
            else
            {
                return(cbrType.cbr_OK);
            }
        }
예제 #2
0
        bool ProcessNode(string inString, xpNodeType nodeType, out string outString)
        {
            bool    hr;
            string  node;
            string  attrList;
            int     index = 0;
            string  name;
            int     attrStart;
            char    tmpChar;
            cbrType res;
            bool    hasChildren;
            int     nodeEnd        = 0;
            int     nodeCloseStart = 0;

            outString = string.Empty;
            if (outString == null)
            {
                return(false);
            }
            do
            {
                node     = string.Empty;
                attrList = string.Empty;
                //
                // First eat the spaces (if any) (ignore index)
                //
                hr = EatSpace(inString, out outString, ref index);
                if (hr != true)
                {
                    return(false);
                }

                inString = outString;
                if (inString[0] == '<' && inString[1] == '/')
                {
                    break;
                }

                if (inString[0] != '<')
                {
                    return(false);
                }

                index    = 1;        // set index to beginning of node string;
                node     = inString; // save the original string;
                inString = inString.Substring(1, inString.Length - 1);

                name = string.Empty;
                hr   = GetNodeName(inString, out name, out outString, ref index);
                if (hr != true)
                {
                    return(false);
                }

                inString = outString;

                hr = EatSpace(inString, out outString, ref index);
                if (hr != true)
                {
                    return(false);
                }

                inString = outString;
                //
                // Now get the attribute string.
                //
                attrStart = index;
                hr        = EatAttrList(inString, out outString, ref index);
                if (hr != true)
                {
                    return(hr);
                }

                // Save the old node character.
                tmpChar = node[index];
                // Make the character after the attribute string into a zero
                StringBuilder sb = new StringBuilder(node);
                sb[index] = Convert.ToChar(0);
                node      = sb.ToString();

                // Get the attribute string
                attrList = node.Substring(attrStart, inString.Length - attrStart);
                // Restore the old character.
                sb        = new StringBuilder(node);
                sb[index] = Convert.ToChar(tmpChar);
                node      = sb.ToString();

                inString = outString;

                // Now eat any spaces.
                hr = EatSpace(inString, out outString, ref index);
                if (hr != true)
                {
                    return(false);
                }
                inString = outString;

                nodeEnd = 0;
                // Now we can check to see if this is a self contained node, or a parent node.
                if (inString[0] == '/' && inString[1] == '>')
                {
                    // Save the old node character.
                    tmpChar = node[index + 2];
                    // Make the character after the attribute string into a zero
                    sb            = new StringBuilder(node);
                    sb[index + 2] = Convert.ToChar(0);
                    node          = sb.ToString();

                    //
                    // Now we have the information for this node.  Call the callback function
                    //
                    res = m_callback(m_value, (nodeType == xpNodeType.xpTopNode ? nodeType : xpNodeType.xpStandalone), name, attrList, node);

                    // Restore the old character.
                    sb            = new StringBuilder(node);
                    sb[index + 2] = Convert.ToChar(tmpChar);
                    node          = sb.ToString();
                    hasChildren   = false;
                    index        += 2;
                    inString      = inString.Substring(2, inString.Length - 2);
                }
                else if (inString[0] == '>')
                {
                    hr = FindEndNode(node, ref nodeEnd, ref nodeCloseStart);
                    if (!hr)
                    {
                        return(hr);
                    }

                    // Save the old node character.
                    tmpChar = node[nodeEnd];
                    // Make the character after the attribute string into a zero
                    sb          = new StringBuilder(node);
                    sb[nodeEnd] = Convert.ToChar(0);
                    node        = sb.ToString();

                    //
                    // Now we have the information for this node.  Call the callback function
                    //
                    res = m_callback(m_value, nodeType, name, attrList, node);

                    // Restore the old character.
                    sb          = new StringBuilder(node);
                    sb[nodeEnd] = Convert.ToChar(tmpChar);
                    node        = sb.ToString();
                    hasChildren = true;
                    index++;
                    inString = inString.Substring(1, inString.Length - 1);
                }
                else
                {
                    return(false);
                }

                //
                // Now, if this node has children and the callback did not tell us to skip them,
                // recursively process the children nodes.
                //
                if (res == cbrType.cbr_OK && hasChildren)
                {
                    hr = ProcessNode(inString, xpNodeType.xpParent, out outString);
                    if (!hr)
                    {
                        return(hr);
                    }
                }
                if (hasChildren)
                {
                    inString = inString.Substring(nodeEnd, inString.Length - nodeEnd);
                }
            }while (nodeType != xpNodeType.xpTopNode && hr == true && res != cbrType.cbr_Abort);
            return(hr);
        }