Пример #1
0
        /// <summary>
        /// This function is responsible for parsing the XML
        /// Actually this function will call the exact parse function
        /// depending upon the type of XML Recieved
        /// </summary>
        /// <param name="XMLFilename"> </param>
        /// <param name="outStruct"> </param>
        /// <param name="TagName"> </param>
        public int ParseXML(string XMLFilename, out XMLSTRUCT outStruct, string TagName)
        {
            // Declare and initializes the iElements to 0
            int iElements = 0;

            // Initializes the outStruct variable of this function
            // this structure is used to store the values of parsed XML
            outStruct = new XMLSTRUCT();

            // The following 12 lines of code checks the Type of XML recieved
            // and calls are made to there corresponding parser function
            // which actually are reponsible for parsing the XML
            // all the parse functions are user defined functions
            // the Number of Parsed records are stores in the iElements
            // variable which is returned by the function
            if (0 == TagName.CompareTo("AUTH"))
            {
                iElements = ParseAUTHXML(XMLFilename, out outStruct);
            }
            else if (0 == TagName.CompareTo("USERLIST"))
            {
                iElements = ParseUSERLISTXML(XMLFilename, out outStruct);
            }
            else if (0 == TagName.CompareTo("SHOWFILES"))
            {
                iElements = ParseSHOWFILESXML(XMLFilename, out outStruct);
            }
            else if (0 == TagName.CompareTo("SEARCH"))
            {
                iElements = ParseSHOWFILESXML(XMLFilename, out outStruct);
            }
            else if (0 == TagName.CompareTo("ERROR"))
            {
                iElements = ParseERRORXML(XMLFilename, out outStruct);
            }
            else if (0 == TagName.CompareTo("SERVERSEARCH"))
            {
                iElements = ParseSERVERSEARCHXML(XMLFilename, out outStruct);
            }
            else if (0 == TagName.CompareTo("CHAT"))
            {
                iElements = ParseCHATXML(XMLFilename, out outStruct);
            }

            // Returns the iElements variable to the calling function
            return(iElements);
        }
Пример #2
0
        /// <summary>
        /// Actual Parsing of ERROR XML
        /// </summary>
        /// <param name="Filename"> </param>
        /// <param name="outStruct"> </param>
        protected int ParseERRORXML(string Filename, out XMLSTRUCT outStruct)
        {
            // initializes all the required variables
            InitVariables();

            // Initialize outStruct variable of this function
            outStruct = new XMLSTRUCT();

            // Process the XML document syncronously
            document.async = false;

            // load the xml document in memory for parsing
            if (document.load(Filename))
            {
                // get the first element of the XML
                element = document.documentElement;

                // get the first child of the element
                node = element.firstChild;

                // extracts the node list present under the node
                nodeList = node.childNodes;

                // iTags will assigns to the number of nodes present
                // in node list
                iTags = nodeList.length;

                // Initialize the ERROR sructure of the outStruct
                // variable
                outStruct.ERROR = new XMLSTRUCT.__ERROR();

                // move the node to the next node of the nodelist
                node = nodeList.nextNode();

                // Extract each value from its specific node
                for (iCounter = 0; iCounter < iTags; iCounter++)
                {
                    // gets the attribute map that is how many attributes
                    // are present in the node
                    nodeMap = node.attributes;

                    // extract the next node from the node map
                    ChildNode = nodeMap.nextNode();

                    // The following 9 lines of code will extract the
                    // various attribute values from the XML node
                    // and fills it to the outStruct's corresponding
                    // structure
                    do
                    {
                        if (0 == ChildNode.nodeName.CompareTo("errorcode"))
                        {
                            outStruct.ERROR.iErrCode = Convert.ToInt32(ChildNode.nodeValue);
                        }
                        else if (0 == ChildNode.nodeName.CompareTo("severity"))
                        {
                            outStruct.ERROR.sSeverity = ChildNode.nodeValue.ToString();
                        }
                        else if (0 == ChildNode.nodeName.CompareTo("description"))
                        {
                            outStruct.ERROR.sDescription = ChildNode.nodeValue.ToString();
                        }
                    } while(null != (ChildNode = nodeMap.nextNode()));

                    // now move to next node
                    node = nodeList.nextNode();
                }
            }

            // Return the number of nodes parsed for the values
            return(iCounter == iTags?iCounter:0);
        }