私は現在、ASP.NET Web フォーム プロジェクトに取り組んでおり、求人情報ページのネストされたリピーターを使用して、逆シリアル化された XML データを表示する必要があります。
私が抱えている問題は、ネストされたリピーターが XMLElement である最初のアイテムのみを表示し、要素の一部である XMLAttribute からのデータを表示しないことです。
たとえば、XML データは次のようになります。
ジョブ.xml
<Jobs>
<Job Category="Administration" Title="Senior Human Resource Coordinator">
<Description>
<![CDATA[ Long description of the job goes here. ]]>
</Description>
<ShortDescription>
<![CDATA[ Short description of the job goes here. ]]>
</ShortDescription>
<JobLocations>
<Location Salary="$50000">Toronto</Location>
<Location Salary="£40000">London</Location>
</JobLocations>
<Benefits>Drug, Dental, Optical and Extended Healthcare Benefits</Benefits>
<Jobtype>Full-Time</Jobtype>
</Job>
<Job Category="Administration" Title="Junior Human Resource Coordinator">
<Description>
<![CDATA[ Long description of the job goes here. ]]>
</Description>
<ShortDescription>
<![CDATA[ Short description of the job goes here. ]]>
</ShortDescription>
<JobLocations>
<Location Salary="$50000">Toronto</Location>
<Location Salary="£40000">London</Location>
</JobLocations>
<Benefits>Drug, Dental, Optical and Extended Healthcare Benefits</Benefits>
<Jobtype>Full-Time</Jobtype>
</Job>
</Jobs>
私が達成しようとしているのは、最初のリピーターが「ジョブ」を循環し、カテゴリ、タイトル、説明などを表示することです。ネストされたリピーターには、ジョブの場所とその給与が表示されます。
たとえば、上に表示された XML データの結果は次のようになります。
- カテゴリ: 管理
- 役職: シニア人事コーディネーター
- 説明: ...
- 簡単な説明: ...
- 場所: トロント
- 給与: $50000
- ...
次に、同じ仕事について、データを再度表示しますが、他の場所と給与を表示します...
- カテゴリ: 管理
- 役職: シニア人事コーディネーター
- 説明: ...
- 簡単な説明: ...
- 場所: ロンドン
- 給与: カテゴリ: 管理
- 役職: シニア人事コーディネーター
- 説明: ...
- 簡単な説明: ...
- 場所: ロンドン
- 給与:£40000
現在、ネストされたリピーターは最初の勤務地のみを表示し、給与については何も表示せず、同じ仕事の他の場所と給与を表示せずに次の仕事に進みます。これは、.aspx ファイルのリピーターの構造に間違いがあったためなのか、XML データの逆シリアル化に使用した .cs ファイルに間違いがあったためなのかはわかりません。以下のコードを確認してください。
Jobs.cs
[Serializable]
public class Job
{
[XmlAttribute]
public string Category { get; set; }
[XmlAttribute]
public string Title { get; set; }
[XmlElement]
public string Description { get; set; }
[XmlElement]
public string ShortDescription { get; set; }
public string Benefits { get; set; }
[XmlElement]
public string Jobtype { get; set; }
[XmlElement("JobLocations")]
public List<JobLocation> JobLocations { get; set; }
public class JobLocation
{
[XmlElement("Location")]
public string Location { get; set; }
[XmlAttribute("Salary")]
public string Salary { get; set; }
}
public static List<Job> Load(string path)
{
return SerializerSupport.DeserializeList<Job>(System.IO.Path.Combine(path, "jobs.xml"));
}
}
JobCategories.aspx
<div class="flex-container">
<div class="flex-row">
<!-- Category Repeater -->
<asp:Repeater ID="Job" runat="server" ItemType="COMPANY.Ecommerce.API.Models.Job" SelectMethod="JobGrid_GetData">
<ItemTemplate>
<div class="flex-item">
<div>Title: <%#Item.Title%></div>
<div>S.Desc: <%#Item.ShortDescription%></div>
<asp:Repeater runat="server" ItemType="COMPANY.Ecommerce.API.Models.Job+JobLocation" DataSource="<%#Item.JobLocations%>">
<ItemTemplate>
<div>Location: <%#Item.Location%></div>
<div>Salary: <%#Item.Salary%></div>
</ItemTemplate>
</asp:Repeater>
<div>
</div>
<div>Category: <%#Item.Category%></div>
<div>Jobtype: <%#Item.Jobtype%></div>
<div>Benefits: <%#Item.Benefits%></div>
<div>Desc: <%#Item.Description%></div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>