Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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# 需要使用Linq to xml在Gridview中显示所有xml记录。我需要可以用来显示xml数据的代码 这是XML文档。我想使用Linq to XML将XML数据绑定到GridView。我想从title_rec元素获取数据。大约有94条记录:- 2012 11 15 05 00 颗粒物 PST 2012 11 19 01 04 颗粒物 PST 277 312 003 1980 05 31 2011 05 31 13897 1. 85 277 312 003 1980 05 31 2011 05 31 数据跟踪/响应/搜索组/搜索对象/搜索单元/标题报告/标题记录/日期 13897 1. 85 平台尚未得到验证 1980 11 03 1. 1980 11 03 13897 1. 85 08 0052337 04 SR 1980 11 03 1980 11 03 1980 11 10 2. 1980 11 10 13897 1. 85 08 0052337 04 SR 1980 11 10 1980 11 10 1980 11 13 3. 1980 11 13 13897 1. 85 08 0052600 04 SR 1980 11 13 1980 11 13 1980 11 25 4. 13897 1. 85 1980 220434 RL 1980 11 25 1980 11 25 1980.220434 唱片所有者 9 80 139134 禁止搜查毗邻物业 禁止所有追踪搜索_C#_Xml_Linq - Fatal编程技术网

C# 需要使用Linq to xml在Gridview中显示所有xml记录。我需要可以用来显示xml数据的代码 这是XML文档。我想使用Linq to XML将XML数据绑定到GridView。我想从title_rec元素获取数据。大约有94条记录:- 2012 11 15 05 00 颗粒物 PST 2012 11 19 01 04 颗粒物 PST 277 312 003 1980 05 31 2011 05 31 13897 1. 85 277 312 003 1980 05 31 2011 05 31 数据跟踪/响应/搜索组/搜索对象/搜索单元/标题报告/标题记录/日期 13897 1. 85 平台尚未得到验证 1980 11 03 1. 1980 11 03 13897 1. 85 08 0052337 04 SR 1980 11 03 1980 11 03 1980 11 10 2. 1980 11 10 13897 1. 85 08 0052337 04 SR 1980 11 10 1980 11 10 1980 11 13 3. 1980 11 13 13897 1. 85 08 0052600 04 SR 1980 11 13 1980 11 13 1980 11 25 4. 13897 1. 85 1980 220434 RL 1980 11 25 1980 11 25 1980.220434 唱片所有者 9 80 139134 禁止搜查毗邻物业 禁止所有追踪搜索

C# 需要使用Linq to xml在Gridview中显示所有xml记录。我需要可以用来显示xml数据的代码 这是XML文档。我想使用Linq to XML将XML数据绑定到GridView。我想从title_rec元素获取数据。大约有94条记录:- 2012 11 15 05 00 颗粒物 PST 2012 11 19 01 04 颗粒物 PST 277 312 003 1980 05 31 2011 05 31 13897 1. 85 277 312 003 1980 05 31 2011 05 31 数据跟踪/响应/搜索组/搜索对象/搜索单元/标题报告/标题记录/日期 13897 1. 85 平台尚未得到验证 1980 11 03 1. 1980 11 03 13897 1. 85 08 0052337 04 SR 1980 11 03 1980 11 03 1980 11 10 2. 1980 11 10 13897 1. 85 08 0052337 04 SR 1980 11 10 1980 11 10 1980 11 13 3. 1980 11 13 13897 1. 85 08 0052600 04 SR 1980 11 13 1980 11 13 1980 11 25 4. 13897 1. 85 1980 220434 RL 1980 11 25 1980 11 25 1980.220434 唱片所有者 9 80 139134 禁止搜查毗邻物业 禁止所有追踪搜索,c#,xml,linq,C#,Xml,Linq,我创建了类TitleByApn&编写linqtoxml查询来解析XML数据。请查找下面的类详细信息和返回查询输出的代码。请使用此代码,或者如果您可以提供一些其他代码与不同的逻辑,这也是很好的 This is XML Document.I want to bind XML data to GridView using Linq to XML .I want data from title_rec element.There are near about 94 records. :- <

我创建了类TitleByApn&编写linqtoxml查询来解析XML数据。请查找下面的类详细信息和返回查询输出的代码。请使用此代码,或者如果您可以提供一些其他代码与不同的逻辑,这也是很好的

This is XML Document.I want to bind XML data to GridView using Linq to XML .I want data from title_rec element.There are near about 94 records.  :-
  <?xml version="1.0" encoding="UTF-8" ?>
 <dtg>
 <search_header>
 <plant_currency>
 <thru_date>
  <year>2012</year>
  <month>11</month>
  <day>15</day>
  </thru_date>
 <thru_time>
  <hour>05</hour>
  <minute>00</minute>
  <ampm>PM</ampm>
  <timezone>PST</timezone>
  </thru_time>
  </plant_currency>
 <search_date>
  <year>2012</year>
  <month>11</month>
  <day>19</day>
  </search_date>
 <search_time>
  <hour>01</hour>
  <minute>04</minute>
  <ampm>PM</ampm>
  <timezone>PST</timezone>
  </search_time>
  </search_header>
 <search_object type="PROPERTY" outcome="SUCCESS">
 <accepted_param>
 <title_param>
 <property_legal type="TITLE_BY_APN">
 <apn>
  <book>277</book>
  <page>312</page>
  <parcel>003</parcel>
  </apn>
  <QS n="XP" v="XA277}312 003" l="T" />
  </property_legal>
 <from_date>
  <year>1980</year>
  <month>05</month>
  <day>31</day>
  </from_date>
 <thru_date>
  <year>2011</year>
  <month>05</month>
  <day>31</day>
  </thru_date>
  <qualifier extended_names="YES" tt_options="SAP" />
  </title_param>
  </accepted_param>
 <search_unit type="PROPERTY" report_occurrence="01" report_count="03" outcome="SUCCESS">
 <search_param>
 <title_param>
 <property_legal type="TRACT">
 <plat type="TRACT">
 <tract>
  <number>13897</number>
  <id>1</id>
  </tract>
  </plat>
  <lot>85</lot>
 <apn>
  <book>277</book>
  <page>312</page>
  <parcel>003</parcel>
  </apn>
  <QS n="SL" v="T 13897 1$[85" l="L" />
  </property_legal>
 <from_date>
  <year>1980</year>
  <month>05</month>
  <day>31</day>
  </from_date>
 <thru_date>
  <year>2011</year>
  <month>05</month>
  <day>31</day>
  </thru_date>
  <qualifier extended_names="YES" tt_options="SAP" />
  </title_param>
  </search_param>
 <filters>
 <filter type="SORT">
 <path collate="ASCENDING">datatrace/response/search_group/search_object/search_unit/title_report/title_rec/date</path>
  </filter>
  </filters>
  <search_desc command="T" type="Tract" short="L:85 T:138971" long="Lot: 85 Tract: 138971" />
 <title_report record_count="91">
 <property_legal type="TRACT">
 <plat type="TRACT">
 <tract>
  <number>13897</number>
  <id>1</id>
  </tract>
  </plat>
  <lot>85</lot>
  <QS n="SL" v="T 13897 1$[85" l="L" />
  <message>PLAT HAS NOT BEEN VERIFIED</message>
  </property_legal>
  <section_index section_id="1" />
 <title_rec section_id="1">
 <date>
  <year>1980</year>
  <month>11</month>
  <day>03</day>
  </date>
  <seq>1</seq>
 <base>
 <base_date>
  <year>1980</year>
  <month>11</month>
  <day>03</day>
  </base_date>
 <property>
 <property_legal type="TRACT">
 <plat type="TRACT">
 <tract>
  <number>13897</number>
  <id>1</id>
  </tract>
  </plat>
  <lot>85</lot>
  <QS n="SL" v="T 13897 1$[85" l="L" />
  </property_legal>
  </property>
 <company>
  <number>08</number>
  </company>
 <order>
  <number>0052337</number>
  <tof>04</tof>
  </order>
 <inst>
  <type>SR</type>
 <recorded>
  <year>1980</year>
  <month>11</month>
  <day>03</day>
  </recorded>
 <posted>
  <year>1980</year>
  <month>11</month>
  <day>03</day>
  </posted>
  </inst>
  </base>
  </title_rec>
 <title_rec section_id="1">
 <date>
  <year>1980</year>
  <month>11</month>
  <day>10</day>
  </date>
  <seq>2</seq>
 <base>
 <base_date>
  <year>1980</year>
  <month>11</month>
  <day>10</day>
  </base_date>
 <property>
 <property_legal type="TRACT">
 <plat type="TRACT">
 <tract>
  <number>13897</number>
  <id>1</id>
  </tract>
  </plat>
  <lot>85</lot>
  <QS n="SL" v="T 13897 1$[85" l="L" />
  </property_legal>
  </property>
 <company>
  <number>08</number>
  </company>
 <order>
  <number>0052337</number>
  <tof>04</tof>
  </order>
 <inst>
  <type>SR</type>
 <recorded>
  <year>1980</year>
  <month>11</month>
  <day>10</day>
  </recorded>
 <posted>
  <year>1980</year>
  <month>11</month>
  <day>10</day>
  </posted>
  </inst>
  </base>
  </title_rec>
 <title_rec section_id="1">
 <date>
  <year>1980</year>
  <month>11</month>
  <day>13</day>
  </date>
  <seq>3</seq>
 <base>
 <base_date>
 <year>1980</year>
  <month>11</month>
 <day>13</day>
  </base_date>
 <property>
 <property_legal type="TRACT">
 <plat type="TRACT">
 <tract>
  <number>13897</number>
  <id>1</id>
  </tract>
  </plat>
  <lot>85</lot>
  <QS n="SL" v="T 13897 1$[85" l="L" />
  </property_legal>
  </property>
 <company>
  <number>08</number>
  </company>
 <order>
  <number>0052600</number>
  <tof>04</tof>
  </order>
 <inst>
  <type>SR</type>
 <recorded>
  <year>1980</year>
  <month>11</month>
  <day>13</day>
  </recorded>
 <posted>
  <year>1980</year>
  <month>11</month>
  <day>13</day>
  </posted>
  </inst>
  </base>
  </title_rec>
 <title_rec section_id="1">
 <date>
  <year>1980</year>
  <month>11</month>
  <day>25</day>
  </date>
  <seq>4</seq>
 <title_doc>
 <property>
 <property_legal type="TRACT">
<plat type="TRACT">
 <tract>
  <number>13897</number>
  <id>1</id>
  </tract>
  </plat>
  <lot>85</lot>
  <QS n="SL" v="T 13897 1$[85" l="L" />
  </property_legal>
  </property>
 <inst>
  <year>1980</year>
  <number>220434</number>
  <type>RL</type>
 <recorded>
  <year>1980</year>
  <month>11</month>
  <day>25</day>
  </recorded>
 <posted>
  <year>1980</year>
  <month>11</month>
  <day>25</day>
  </posted>
 <image provider="DATA_TREE" county_fips="065" document_id_desc="DocumentYear.DocID">
 <image_params document_type="DAILY_DOCUMENT" index_type="YEAR.DOCID" document_index_id="16">
  <description>1980.220434</description>
  </image_params>
  </image>
  <QS n="IN" v="Y1980220434" l="B" />
  </inst>
 <party_info>
 <party role="GRANTOR">
  <name>RECORD OWNER</name>
  <QS n="GN" v="RECORD OWNER" l="N" />
  </party>
  </party_info>
 <remarks>
  <len>9</len>
  <text>80 139134</text>
  </remarks>
  </title_doc>
  </title_rec>
  </title_report>
 <commentary>
 <comment>
  <text>ADJOINING PROPERTY SEARCH SUPPRESSED</text>
  </comment>
 <comment>
  <text>ALL TRACT SEARCH SUPPRESSED</text>
  </comment>
  </commentary>
  </search_unit>
  </search_object>
  </dtg>
公共类标题栏
{
私人字符串设保人;
私人字符串受让人;
私有字符串doctype;
私人弦乐器;
私人串月;
私人弦日;
私人弦年;
私人字符串注释;
公共字符串设保人
{获取{返回设保人;}
}
公共字符串受让人
{
获取{return grantee;}
}
公共字符串\u月
{
获取{返回月份;}
}
公共字符串日
{
获取{返回日;}
}
公共字符串\u年
{
获取{返回年份;}
} 
公共字符串\u doctype
{
获取{return doctype;}
}
公共字符串
{
获取{返回备注;}
}
公共弦乐器
{
获取{return instrument;}
}
公共静态列表GetTitle()
{
列表输出=新列表();
字符串filepath=@“C:/Title.xml”;
//XElement xdoc=新XElement();
XElement xdoc=XElement.Load(文件路径);
//XElement=XElement.Parse(文件路径);
//var query=从xdoc.subjects(“title_doc”)中的b开始
//选择b.值;
//字符串查询=(来自xdoc.subjects(“title_doc”)中的b)
//选择b.Value).FirstOrDefault();
int i=0;
字符串s1=“”;
字符串inst=“”;
//字符串s2=“”;
//字符串s3=“”;
//字符串s4=“”;
var authorList=xdoc.substands(“title_doc”).Select(x=>x.Value.ToList();
foreach(authorList中的字符串项)
{
字符串月份=(从xdoc.substands(“title_doc”).substands(“recorded”)中的o开始)
选择o.Element(“month”).Value.First();
字符串日期=(从xdoc.substands(“title_doc”).substands(“recorded”)中的o开始)
选择o.Element(“day”).Value.First();
字符串年份=(从xdoc.substands(“title_doc”).substands(“recorded”)中的o开始)
选择o.Element(“年”).Value.First();
字符串授予人=(从xdoc.subjections(“title\u doc”).subjections(“party\u info”).subjections(“party”)中的o开始)
其中o.Attribute(“角色”).Value==“授予人”
选择o.Element(“name”).Value).FirstOrDefault();
////选择新仪器()
////{
////授予人=(字符串)o.Element(“名称”)
////};
字符串受让人=(从xdoc.后代(“所有权文件”)中的o开始)。后代(“当事人信息”)。后代(“当事人”)
其中o.Attribute(“角色”).Value==“被授权人”
选择o.Element(“name”).Value.First();
字符串Doctype=(xdoc.substands(“title_doc”).substands(“inst”)中的o)
选择o.Element(“type”).Value.First();
字符串instNo=(从xdoc.substands(“title_doc”).substands(“inst”)中的o开始)
选择o.Element(“number”).Value.First();
字符串备注=(从xdoc.substands(“title_doc”).substands(“备注”)中的o开始)
选择o.Element(“text”).Value.First();
输出。添加(新标题栏(授予人、受让人、月、日、年、instNo、Doctype、备注));
}
返回输出;
} 
}
这是负责将类绑定到gridview的代码:
GridView1.DataSource=titleByPN.GetTitle();
GridView1.DataBind();
我知道,因为FirstOrDefault()只有第一条记录显示在gridview中。
我希望代码显示gridview中的所有记录。
请尽快帮助我。
提前谢谢。

根据问题的内容,听起来您已经解析了XML并将其放入了上面创建的类中。本教程位于Codeplex上,标题为“深入介绍了如何将类绑定到DataGridView以及访问修饰符等

本质上,一旦创建GridView,就可以将BindingSource对象添加到它的数据项中
public class TitleByApn
{
 private string grantor;
 private string grantee;
 private string doctype;
 private string instrument;
 private string month;
 private string  day;
 private string  year;
 private string remarks;

 public string _grantor
{  get { return grantor; }
}

public string _grantee
{
 get {return grantee ;}
}

public string _month
{
 get {return month; }
}

public string _day
{
 get {return day; }
}

public string _year
{
 get { return year; }
} 

public string _doctype
{
get{ return doctype; }
}

public string  _remarks
{
get {return remarks;}
}

public string  _instrument
{
get {return instrument; }
}

public static List<TitleByApn> GetTitle()


        {

            List<TitleByApn> output = new List<TitleByApn>();
            string filepath = @"C:/Title.xml";

            //XElement xdoc = new XElement();

              XElement xdoc =   XElement.Load(filepath);

            //XElement xElement = XElement.Parse(filepath);

            //var query = from b in xdoc.Descendants("title_doc")
            //            select b.Value;

            //string query = (from b in xdoc.Descendants("title_doc")
            //                select b.Value).FirstOrDefault();

            int i = 0;
            string s1 = "";
            string inst = "";
            //string s2 = "";
            //string s3 = "";
            //string s4 = "";
            var authorList = xdoc.Descendants("title_doc").Select(x => x.Value).ToList();
            foreach (string item in authorList)
            {


                     string Month = (from o in xdoc.Descendants("title_doc").Descendants("recorded")
                                 select o.Element("month").Value).First();

                string Day = (from o in xdoc.Descendants("title_doc").Descendants("recorded")
                               select o.Element("day").Value).First();

                string Year = (from o in xdoc.Descendants("title_doc").Descendants("recorded")
                                select o.Element("year").Value).First();

                string granTor = (from o in xdoc.Descendants("title_doc").Descendants("party_info").Descendants("party")
                                   where o.Attribute("role").Value == "GRANTOR"
                                  select o.Element("name").Value).FirstOrDefault();
                ////select new Instrument()

                ////{
                ////    Grantor = (string)o.Element("name")

                ////};

                string granTee = (from o in xdoc.Descendants("title_doc").Descendants("party_info").Descendants("party")
                                   where o.Attribute("role").Value == "GRANTEE"
                                  select o.Element("name").Value).First();

                string Doctype =(from o in xdoc.Descendants("title_doc").Descendants("inst")
                                   select o.Element("type").Value).First();

                 string instNo = (from o in xdoc.Descendants("title_doc").Descendants("inst")
                                   select o.Element("number").Value).First();

                  string REmarks = (from o in xdoc.Descendants("title_doc").Descendants("remarks")
                                   select o.Element("text").Value).First();

               output.Add(new TitleByApn(granTor, granTee, Month, Day, Year,instNo, Doctype, REmarks));


                }


            return output;
             } 

}

This is the code responsible to bind the class to gridview:
GridView1.DataSource = TitleByApn.GetTitle();
            GridView1.DataBind();


I know because of FirstOrDefault() only first record is displaying in gridview.
I want code to display all the records in gridview.
Please help me ASAP.
Thanks in advance.
private void Form1_Load(object sender, EventArgs e)
{
 airplaneBindingSource.Add(new Airplane("Boeing 747", 800));
  airplaneBindingSource.Add(new Airplane("Airbus A380", 1023));
  airplaneBindingSource.Add(new Airplane("Cessna 162", 67));
}