Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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_C# 4.0 - Fatal编程技术网

C# 从可通过枚举的XML文件创建类

C# 从可通过枚举的XML文件创建类,c#,.net,xml,c#-4.0,C#,.net,Xml,C# 4.0,我尝试使用xsd.exe为我的xml创建一个类,它似乎可以工作,但我可以枚举该类。我甚至尝试使用XSD2代码,但这会导致以下错误:当我尝试使用XSD2代码时,“出现了一个反映“MySQlXML.XBMC”类型的错误” 列举清单。请让我知道,如果你有任何想法,我可以让枚举工作 这是我的xml <?xml version="1.0" encoding="utf-8"?> <XBMC> <Show> <IdShow>1</IdShow&

我尝试使用xsd.exe为我的xml创建一个类,它似乎可以工作,但我可以枚举该类。我甚至尝试使用XSD2代码,但这会导致以下错误:当我尝试使用XSD2代码时,“出现了一个反映“MySQlXML.XBMC”类型的错误” 列举清单。请让我知道,如果你有任何想法,我可以让枚举工作

这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<XBMC>
  <Show>
    <IdShow>1</IdShow>
    <TheTvDbId>248741</TheTvDbId>
    <ShowName>2 Broke Girls</ShowName>
    <Seasons>
      <Season>
        <Number>1</Number>
        <Path>\\10.0.0.3\tv\2 Broke Girls\Season1\</Path>
      </Season>
      <Season>
        <Number>3</Number>
        <Path>\\10.0.0.3\tv\2 Broke Girls\Season 03\</Path>
      </Season>
    </Seasons>
  </Show>
  <Show>
    <IdShow>164</IdShow>
    <TheTvDbId>75682</TheTvDbId>
    <ShowName>Bones</ShowName>
    <Seasons>
      <Season>
        <Number>1</Number>
        <Path>\\10.0.0.3\TV2\Bones\Season 01\</Path>
      </Season>
    </Seasons>
  </Show>
</XBMC>
这是生成的类xsd.exe

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;


namespace MySQlXML
{  
    /// <remarks/>
    public partial class XBMC
    {

        private XBMCShow[] showField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Show")]
        public XBMCShow[] Show
        {
            get
            {
                return this.showField;
            }
            set
            {
                this.showField = value;
            }
        }
    }

    /// <remarks/>

    public partial class XBMCShow
    {

        public ushort idShowField;

        public string theTvDbIdField;

        public string showNameField;

        private XBMCShowSeason[] seasonsField;

        /// <remarks/>
        public ushort IdShow
        {
            get
            {
                return this.idShowField;
            }
            set
            {
                this.idShowField = value;
            }
        }

        /// <remarks/>
        public string TheTvDbId
        {
            get
            {
                return this.theTvDbIdField;
            }
            set
            {
                this.theTvDbIdField = value;
            }
        }

        /// <remarks/>
        public string ShowName
        {
            get
            {
                return this.showNameField;
            }
            set
            {
                this.showNameField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayItemAttribute("Season", IsNullable = false)]
        public XBMCShowSeason[] Seasons
        {
            get
            {
                return this.seasonsField;
            }
            set
            {
                this.seasonsField = value;
            }
        }
    }

    /// <remarks/>

    public partial class XBMCShowSeason
    {

        private byte numberField;

        private string pathField;

        /// <remarks/>
        public byte Number
        {
            get
            {
                return this.numberField;
            }
            set
            {
                this.numberField = value;
            }
        }

        /// <remarks/>
        public string Path
        {
            get
            {
                return this.pathField;
            }
            set
            {
                this.pathField = value;
            }
        }
    }

}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Xml.Serialization;
名称空间MySQlXML
{  
/// 
公共部分类XBMC
{
私人XBMCShow[]展示区;
/// 
[System.Xml.Serialization.XmlElementAttribute(“显示”)]
公共XBMCShow[]秀
{
得到
{
返回此.showField;
}
设置
{
this.showField=值;
}
}
}
/// 
公共部分类XBMCShow
{
公共住宅区;
公共字符串字段;
公共字符串showNameField;
私人XBMCShowSeason[]季候场;
/// 
公共卫生服务
{
得到
{
返回此.idShowField;
}
设置
{
this.idShowField=值;
}
}
/// 
公共字符串投标
{
得到
{
返回此.ThetVDBid字段;
}
设置
{
this.theTvDbIdField=值;
}
}
/// 
公共字符串ShowName
{
得到
{
返回此.showname字段;
}
设置
{
this.showNameField=值;
}
}
/// 
[System.Xml.Serialization.XmlArrayItemAttribute(“Season”,IsNullable=false)]
公众XBMCShowSeason[]季节
{
得到
{
把这个还给我;
}
设置
{
this.季候字段=值;
}
}
}
/// 
公共部分类XBMCShowSeason
{
专用字节数字段;
私有字符串路径域;
/// 
公共字节号
{
得到
{
返回此.numberField;
}
设置
{
this.numberField=值;
}
}
/// 
公共字符串路径
{
得到
{
返回这个.pathField;
}
设置
{
this.pathField=值;
}
}
}
}
试试:


你错过了点播部分

好的,谢谢,最后一件事我该如何选择“骨骼”例如,从数组中显示很酷,如果我想在整个数组中执行相同的操作而不进行外循环,那该怎么办?通常,你可以使用数组索引,但这不是一个选项。如果你想要这样的东西,请使用
test.show[]。ShowName==“Bones”
,你可以使用LINQ。但要搜索集合中的某个项,您无论如何都需要进行迭代。要么在for/while循环中执行,要么让LINQ执行。某个地方或另一个地方会出现一个循环。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;


namespace MySQlXML
{  
    /// <remarks/>
    public partial class XBMC
    {

        private XBMCShow[] showField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Show")]
        public XBMCShow[] Show
        {
            get
            {
                return this.showField;
            }
            set
            {
                this.showField = value;
            }
        }
    }

    /// <remarks/>

    public partial class XBMCShow
    {

        public ushort idShowField;

        public string theTvDbIdField;

        public string showNameField;

        private XBMCShowSeason[] seasonsField;

        /// <remarks/>
        public ushort IdShow
        {
            get
            {
                return this.idShowField;
            }
            set
            {
                this.idShowField = value;
            }
        }

        /// <remarks/>
        public string TheTvDbId
        {
            get
            {
                return this.theTvDbIdField;
            }
            set
            {
                this.theTvDbIdField = value;
            }
        }

        /// <remarks/>
        public string ShowName
        {
            get
            {
                return this.showNameField;
            }
            set
            {
                this.showNameField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayItemAttribute("Season", IsNullable = false)]
        public XBMCShowSeason[] Seasons
        {
            get
            {
                return this.seasonsField;
            }
            set
            {
                this.seasonsField = value;
            }
        }
    }

    /// <remarks/>

    public partial class XBMCShowSeason
    {

        private byte numberField;

        private string pathField;

        /// <remarks/>
        public byte Number
        {
            get
            {
                return this.numberField;
            }
            set
            {
                this.numberField = value;
            }
        }

        /// <remarks/>
        public string Path
        {
            get
            {
                return this.pathField;
            }
            set
            {
                this.pathField = value;
            }
        }
    }

}
foreach (XBMCShow show in test.Show) {
                               ----
                                 ^

     if(show.ShowName == "Bones") {
         ...