views:

83

answers:

1

I have a website that needs to pull information from two diffferent XML data sources. Originally I only need to get the data from one source so I was building a URL in the backend that went and retrieved the data from the XML site and then parsed and rendered it in the front end of the website.

Now I have to use a 2nd data source and merge the result sets (which are identically structured XML) into one result set.

Here is the code I am currently using to get one XML feed.

sUrl = sbUrl.ToString(); //The URL for the XML feed

    XmlDocument xDoc = new XmlDocument();

    StringBuilder oBuilder = new StringBuilder(); //The parsed HTML output

    XmlTextReader oXmlReader = new XmlTextReader(sUrl);
    oXmlReader.Read();
    xDoc.Load(oXmlReader);


     XmlNodeList List = xDoc.GetElementsByTagName("result");
    foreach (XmlNode node in List)
    {
        XmlElement key = (XmlElement)node;
        //BUILD THE OUTPUT HERE


    }

Thanks in advance for your help.

A: 

You can use:

  • Linq2Xml
  • Convert the XML representation in C# Objects and merge the results in an Array (so you cans sort/filter the data)
  • encapsulate your parsing code block into a method and call that method for each source.
Arthur