Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用c#从这个XML中读取数据?_C#_.net_Xml_.net 4.5 - Fatal编程技术网

如何用c#从这个XML中读取数据?

如何用c#从这个XML中读取数据?,c#,.net,xml,.net-4.5,C#,.net,Xml,.net 4.5,您正在忽略XML名称空间。您可以尝试: void getfromxml() { XmlDocument doc = new XmlDocument(); doc.LoadXml(vboxxml); XmlNodeList nodes = doc.DocumentElement.SelectNodes("/VirtualBox/Global/MachineRegistry/Machine

您正在忽略XML名称空间。您可以尝试:

        void getfromxml()
        {

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(vboxxml);


            XmlNodeList nodes  = doc.DocumentElement.SelectNodes("/VirtualBox/Global/MachineRegistry/MachineEntry");

            int i = 0;
            foreach (XmlNode node in nodes)
            {
                machines[i,0] = node.Attributes["uuid"].Value;
                machines[i,1] = node.Attributes["src"].Value;

                i++;
            }



        }

(使用HeLoopalNAME()函数扩展其他级别,如果需要)

您也可以考虑使用<代码> xObjs类。
        void getfromxml()
        {

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(vboxxml);


            XmlNodeList nodes  = doc.DocumentElement.SelectNodes("/VirtualBox/Global/MachineRegistry/MachineEntry");

            int i = 0;
            foreach (XmlNode node in nodes)
            {
                machines[i,0] = node.Attributes["uuid"].Value;
                machines[i,1] = node.Attributes["src"].Value;

                i++;
            }



        }
XmlNodeList nodes  = doc.DocumentElement.SelectNodes("//*[local-name()='MachineEntry']");