Reading multiple child nodes of xml file

后端 未结 3 631
挽巷
挽巷 2020-12-17 15:33

I have created an Xml file with example contents as follows:



  

        
3条回答
  •  忘掉有多难
    2020-12-17 16:09

    go thru this

     public static void XMLNodeCheck(XmlNode xmlNode)
        {
            if (xmlNode.HasChildNodes)
            {
                foreach (XmlNode node in xmlNode)
                {
                    if (node.HasChildNodes)
                    {
                        Console.WriteLine(node.Name);
                        if (node.Attributes.Count!=0)
                        {
                            foreach (XmlAttribute att in node.Attributes)
                            {
                                Console.WriteLine("----------" + att.Name + "----------" + att.Value);
                            }
                        }
    
                        XMLNodeCheck(node);//recursive function 
                    }
                    else
                    {
                        if (!node.Equals(XmlNodeType.Element))
                        {
                            Console.WriteLine(node.InnerText);
                        }
    
                    }
                }
            }
        }
    

提交回复
热议问题