⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clsxmlparser.cs

📁 一个p2p的c#版源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
			return iCounter==iTags?iCounter:0;
		}
		
		/// <summary>
		/// Actual Parsing of AUTHENTICATION XML
		/// </summary>
		/// <param name="Filename"> </param>
		/// <param name="outStruct"> </param>
		protected int ParseAUTHXML(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 AUTH sructure of the outStruct
				// variable
				outStruct.AUTH = new XMLSTRUCT.__AUTHENTICATION();
				
				// 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("code") )
							outStruct.AUTH.iCode =  Convert.ToInt32(ChildNode.nodeValue);
						else if( 0 == ChildNode.nodeName.CompareTo("status") )
							outStruct.AUTH.sStatus = ChildNode.nodeValue.ToString();
						else if( 0 == ChildNode.nodeName.CompareTo("ip") )
							outStruct.AUTH.sIPAddress = 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;
		}

		/// <summary>
		/// Actual Parsing of USERLIST XML
		/// </summary>
		/// <param name="Filename"> </param>
		/// <param name="outStruct"> </param>
		protected int ParseUSERLISTXML(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 USERLIST sructure of the outStruct
				// variable
				outStruct.USERLIST = new XMLSTRUCT.__USERLIST[iTags];

				// 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("username") )
							outStruct.USERLIST[iCounter].sUsername = ChildNode.nodeValue.ToString();
						else if( 0 == ChildNode.nodeName.CompareTo("ip") )
							outStruct.USERLIST[iCounter].sIPAddress = 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;
		}
	
		/// <summary>
		/// Actual Parsing of SERVERSEARCH XML
		/// </summary>
		/// <param name="Filename"> </param>
		/// <param name="outStruct"> </param>
		protected int ParseSERVERSEARCHXML(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 SERVERSEARCH sructure of the outStruct
				// variable
				outStruct.SERVERSEARCH = new XMLSTRUCT.__SERVERSEARCH[iTags];

				// 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("ip") )
							outStruct.SERVERSEARCH[iCounter].sIPAddress = ChildNode.nodeValue.ToString();
						else if( 0 == ChildNode.nodeName.CompareTo("username") )
							outStruct.SERVERSEARCH[iCounter].sUsername = ChildNode.nodeValue.ToString();
						else if( 0 == ChildNode.nodeName.CompareTo("filename") )
							outStruct.SERVERSEARCH[iCounter].sFilename = 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;
		}

		/// <summary>
		/// Actual Parsing of SHOWFILES XML
		/// </summary>
		/// <param name="Filename"> </param>
		/// <param name="outStruct"> </param>
		protected int ParseSHOWFILESXML(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 SHOWFILES sructure of the outStruct
				// variable
				outStruct.SHOWFILES = new XMLSTRUCT.__SHOWFILES[iTags];

				// 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("filename") )
							outStruct.SHOWFILES[iCounter].sFilename = ChildNode.nodeValue.ToString();
						else if( 0 == ChildNode.nodeName.CompareTo("mask") )
							outStruct.SHOWFILES[iCounter].iMask =  Convert.ToInt32(ChildNode.nodeValue);
						else if( 0 == ChildNode.nodeName.CompareTo("filesize") )
							outStruct.SHOWFILES[iCounter].iFileSize =  Convert.ToInt32(ChildNode.nodeValue);
					} 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;
		}

		/// <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;
		}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -