locked
HOw more than one XML RSS Feed file on the same web page? RRS feed

  • Question

  • User-651208615 posted
    <META content="Microsoft SafeHTML" name=Generator><mce:style></mce:style> <STYLE mce_bogus="1"></STYLE> Hi Community

    When you have an XML RSS Feed file for News, if you want to display Sports and Weather you also need an XML RSS Feed file for those tabs when you are using TabStrip/Multipage web control , so you would need 3 XML RSS Feeds files in all.

    The problem is each one of the XML RSS Feeds files contain a field name “Link” in the file so after the first dataset is loaded with the News RSS XML Feed and it tries to load the next dataset with the Sports XML RSS Feed you get an error stating:

    “A column named 'link' already belongs to this DataTable: cannot set a nested table name to the same name.

    So the question is if you have a TabStrip/Mulitpage that shows tabs for News, Sports and Weather, how can you display them all on the same web page?

    Below is what the code looks like:

    protected void Page_Load(object sender, EventArgs e)
    {

    //bind the results to the repeater
    rssRepeater1.DataSource = GetRSS1(strUrl);
    rssRepeater1.DataBind();
    rssRepeater2.DataSource = GetRSS2(strUrl2);
    rssRepeater2.DataBind();
    rssRepeater3.DataSource = GetRSS3(strUrl);
    rssRepeater3.DataBind();
    }

    private DataTable GetRSS1(string strUrl)
    {
    try
    {
    XmlTextReader xtr1 = new XmlTextReader("http://news.xml");
    DataSet ds1 = new DataSet();
    ds1.ReadXml(xtr1);
    return ds1.Tables[2];
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }

    private DataTable GetRSS2(string strUrl)
    {
    try
    {
    XmlTextReader xtr2 = new XmlTextReader("http://syndicatedContent_categoryId_0.xml");
    DataSet ds2 = new DataSet();
    ds2.ReadXml(xtr2);
    return ds2.Tables[3];
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }

    private DataTable GetRSS3(string strUrl)
    {
    try
    {
    XmlTextReader xtr3 = new XmlTextReader("http://RSS.xml");
    DataSet ds3 = new DataSet();
    ds3.ReadXml(xtr3);
    return ds3.Tables[4];
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }

    <ie:TabStrip id="TabStrip1" runat="server" TargetID="MultiPage1" Height="20px"
    Orientation="Horizontal" TabDefaultStyle="background-color:White"
    TabSelectedStyle="background-color:Aqua">
    <ie:Tab Text="News">
    </ie:Tab>
    <ie:TabSeparator />
    <ie:Tab Text="Sports">
    </ie:Tab>
    <ie:TabSeparator />
    <ie:Tab Text="Weather">
    </ie:Tab>
    </ie:TabStrip>

    <ie:MultiPage id="MultiPage1" runat="server">

    <ie:PageView id="page1">
    <asp:Repeater ID="rssRepeater1" runat="server">

    <ItemTemplate>
    <a href="<%# DataBinder.Eval(Container.DataItem, "link")%>"> <%# DataBinder.Eval(Container.DataItem, "title") %></a><br />
    </ItemTemplate>

    </asp:Repeater>
    </ie:PageView>

    <ie:PageView id="page2">
    <asp:Repeater ID="rssRepeater2" runat="server">

    <ItemTemplate>
    <a href="<%# DataBinder.Eval(Container.DataItem, "link")%>"> <%# DataBinder.Eval(Container.DataItem, "title") %></a><br />
    </ItemTemplate>

    </asp:Repeater>
    </ie:PageView>

    <ie:PageView id="page3">
    <asp:Repeater ID="rssRepeater3" runat="server">

    <ItemTemplate>
    <a href="<%# DataBinder.Eval(Container.DataItem, "link")%>"> <%# DataBinder.Eval(Container.DataItem, "title") %></a><br />
    </ItemTemplate>

    </asp:Repeater>
    </ie:PageView>

    </ie:MultiPage>

    What is the alternative to do this?

    Thank you
    Shabeaut
    Monday, November 15, 2010 8:37 PM

Answers

  • User3866881 posted

    Please paste your xml files and let me see them …… please send a private conversion into the asp.net private email box of

    me and I'll deal with that if I've got free time.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 22, 2010 3:12 AM

All replies

  • User3866881 posted

    This usually happens when you have an XML file whose tags are duplicated, for example:

    <?xml version="1.0" encoding="utf-8" ?>
    <Employees>
      <Employee>
        <EmployeeId>c2e515e9-8feb-4bb5-b6de-3642e3f7157f</EmployeeId>
        <EmployeeName>Bob</EmployeeName>
        <Employees>
          <Employee>
            <EmployeeId>ba3f80be-78a0-499f-92db-4a87843654e1</EmployeeId>
            <EmployeeName>Sue</EmployeeName>
            <Employees />
          </Employee>
        </Employees>
      </Employee>
      <Employee>
        <EmployeeId>535fdfa3-5118-45e6-9596-d2a8e8521e6c</EmployeeId>
        <EmployeeName>Dan</EmployeeName>
        <Employees>
          <Employee>
            <EmployeeId>e5f2b56f-3b91-4254-b827-5164288457b4</EmployeeId>
            <EmployeeName>Ron</EmployeeName>
            <Employees />
          </Employee>
        </Employees>
      </Employee>
      <Employee>
        <EmployeeId>88a0819e-8990-4454-b35e-22fd08f95ed5</EmployeeId>
        <EmployeeName>Mac</EmployeeName>
        <Employees>
          <Employee>
            <EmployeeId>a5d2144b-ef41-441a-9ce3-11d3bc651b89</EmployeeId>
            <EmployeeName>Amy</EmployeeName>
            <Employees />
          </Employee>
        </Employees>
      </Employee>
    </Employees>

    XMl file's values above will raise the error.

    The solution I think is to use LINQ-TO-XML instead, just like this:

    XElement employees = new XElement("Employees",

    from employee in xdoc.Root.Descendants("Employee")

    select new XElement("Employee",

    new XAttribute("id", (string)employee.Element("EmployeeId")),

    new XAttribute("name", (string)employee.Element("EmployeeName")),

    new XAttribute("manager-id", employee.Parent != null && employee.Parent.Parent == null ? string.Empty : (string)employee.Parent.Parent.Element("EmployeeId"))));

    And it will create the xml like this:

    <Employees>
      <Employee id="c2e515e9-8feb-4bb5-b6de-3642e3f7157f" name="Bob" manager-id="" />
      <Employee id="ba3f80be-78a0-499f-92db-4a87843654e1" name="Sue" manager-id="c2e515e9-8feb-4bb5-b6de-3642e3f7157f" />
      <Employee id="535fdfa3-5118-45e6-9596-d2a8e8521e6c" name="Dan" manager-id="" />
      <Employee id="e5f2b56f-3b91-4254-b827-5164288457b4" name="Ron" manager-id="535fdfa3-5118-45e6-9596-d2a8e8521e6c" />
      <Employee id="88a0819e-8990-4454-b35e-22fd08f95ed5" name="Mac" manager-id="" />
      <Employee id="a5d2144b-ef41-441a-9ce3-11d3bc651b89" name="Amy" manager-id="88a0819e-8990-4454-b35e-22fd08f95ed5" />
    </Employees>

    Read the XML and show onto your aspx page.

    Tuesday, November 16, 2010 8:56 PM
  • User-651208615 posted

    Hi Decker Dong

        XML files have a "Title" and a "Link" elements/attributes so by reading in more than one
    XML file there will be duplicates elementattribute  names.  I tried to read the XML files into
    different datasets but got the same error message to avoid ambiguity so I don't know why
    it still gave an error.

        I don't know LINQ but I will give it a try.

        Note:  I do think one of the XML files had something wrong with it because
    it returned an error message.  Only the file that opened successfully actually looked right
    when I view the file the other 2 XML files showed the data going across the page instead
    of down the page like the good file displayed its data.

        Thank you
        Shabeaut

     

       

    Tuesday, November 16, 2010 9:27 PM
  • User-651208615 posted

    Hello Decker Dong

        I created another dataset for the same XML RSS Feeds files so two separate datasets will contain RSS Feeds but now after the first dataset loads the second one gives a different  error stating:

    there is no attribute named  <link> in the file.

        So I opened the second XML RSS Feed file and looked at it and there is a <link> and a <title> inside of the file.

        Since time is a factor in this case I can't do LINQ right now.  So does that
    error tell you what's wrong?

        Note: Whenever I comment the other lines that access the XML files the first
    XML file gets loaded successfully! 

        As I mentioned I think there is something wrong with the other 2 XML files.  Do you know where I can get an working XML file RSS Feeds  for all Sports, and the Weather in New York so that can try them and see if there is still a problem?

        Thanks
        Shabeaut

    Wednesday, November 17, 2010 9:38 PM
  • User3866881 posted

    Please paste your xml files and let me see them …… please send a private conversion into the asp.net private email box of

    me and I'll deal with that if I've got free time.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 22, 2010 3:12 AM