473,395 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Parsing Amazon XML using Linq

Hello All:

I am working on parsing the Amazon Key word search webservice for the
Editorial Reviews Content containing "Amazon.Com Review" in the Source
element.

<EditorialReviews>
<EditorialReview>
<Source>Product Description</Source>
<ContentProd desc ........</Content>
</EditorialReview>
<EditorialReview>
<Source>Amazon.com Review</Source>
<ContentAMZN Review desc *** This Text *****</Content /
</EditorialReview>
</EditorialReviews>
//Call to Parse Editorial Reviews Nodes
Notes = ParseNotes(result.Descendants(ns + "EditorialReviews")),
//Parse Editorial Reviews
private string ParseNotes(IEnumerable<XElementnotesElement)
{
var productDescription = (from notes in
notesElement.Descendants(ns + "EditorialReview")
let source = (string) notes.Element(ns
+ "Source")
where source == "Amazon.com Review"
select new
{
Source = (string)
notes.Element(ns + "Source"),
Content = (string)
notes.Element(ns + "Content")
});

foreach (var s in productDescription)
{
Response.Write(s.Content + "<hr/>");

}

When I loop through the results, the Content that I am looking for is
repeated 2x, how do I write the query so the correct results are only
displayed 1x.
Thanks
Stuart

Oct 15 '08 #1
1 2353
Stuart Shay wrote:
I am working on parsing the Amazon Key word search webservice for the
Editorial Reviews Content containing "Amazon.Com Review" in the Source
element.

<EditorialReviews>
<EditorialReview>
<Source>Product Description</Source>
<ContentProd desc ........</Content>
</EditorialReview>
<EditorialReview>
<Source>Amazon.com Review</Source>
<ContentAMZN Review desc *** This Text *****</Content /
</EditorialReview>
</EditorialReviews>
When I loop through the results, the Content that I am looking for is
repeated 2x, how do I write the query so the correct results are only
displayed 1x.
I can't reproduce the problem. Here is the code I constructed from your
posting:

class Program
{
private static XNamespace ns;
static void Main(string[] args)
{
XDocument doc = XDocument.Parse(@"<EditorialReviews>
<EditorialReview>
<Source>Product Description</Source>
<ContentProd desc ........</Content>
</EditorialReview>
<EditorialReview>
<Source>Amazon.com Review</Source>
<ContentAMZN Review desc *** This Text *****</Content /
</EditorialReview>
</EditorialReviews>");
ns = doc.Root.Name.Namespace;

ParseNotes(doc.Descendants(ns + "EditorialReviews"));
}

private static void ParseNotes(IEnumerable<XElementnotesElement)
{
var productDescription = (from notes in
notesElement.Descendants(ns + "EditorialReview")
let source = (string)
notes.Element(ns + "Source")
where source == "Amazon.com Review"
select new
{
Source = (string)
notes.Element(ns + "Source"),
Content = (string)
notes.Element(ns + "Content")
});

foreach (var s in productDescription)
{
Console.WriteLine(s.Content);

}
}
}

Output is

AMZN Review desc *** This Text *****

without duplicates.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 15 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christophe Vanfleteren | last post by:
Hello, I'm parsing xml that is returned by the Amazon webservices (using their REST interface). Their dev-heavy.xsd has the following entry: <xs:element name="Track"> <xs:complexType>...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
18
by: martin | last post by:
I'm just wondering... Will it be possible to use C# 3.0 and Linq to objects without having our users download the .NET Framework 2.0 client? I really would like to use the C# 3.0 features, but I...
5
by: =?Utf-8?B?U2llZ2ZyaWVkIEhlaW50emU=?= | last post by:
Can someone help me convert this to the latest C# syntax using predicate/delegate? You can see my attempt in the comments. Also: how would I set a new font for q_ul? q_ul is a WPF TextBlock and I...
2
by: Neil Chambers | last post by:
All, I have a class describing various actions to take against a LINQ to SQL datasource. What are the pros/cons of instantiating the LINQ object either in the root of the class (for lack of a...
7
by: shapper | last post by:
Hello, Is it possible to multiply all Prices in a List<Productby 1.1 using Linq? Product has a property named Price. Thanks, Miguel
1
by: codexxx | last post by:
Hi All, We have setup an Amazon webstore and we anticipate uploading 10,000+ products, and therefore to avoid unnecessary manual labor we wish to automate as much of the process of adding and...
5
by: CSharper | last post by:
I have a hashtable which has key and value. If the key is set to 'a' then I need to create a class1 and if it has key 'b' then I need to create class2 etc. (There is no name relation between the...
8
by: =?Utf-8?B?TTFpUw==?= | last post by:
I’m trying to parse out Amazon S3 server logs which are space delimited. However date fields are in the following form: When I try to use the following code to split the record on the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.