Hi, I've been playing with the new Bing API, for web results, which returns XML in the following format (apologies for the length, but it won't make sense otherwise):
<feed> <title type="text">xbox</title> <subtitle type="text">Bing Web Search</subtitle> <id>https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/v1/Web?Q +uery='xbox'&Market='en-GB'&$top=3</id> <rights type="text"/> <updated>2013-03-13T19:01:31Z</updated> <link rel="next" href="https://api.datamarket.azure.com/Data.ashx/Bing +/SearchWeb/v1/Web?Query='xbox'&Market='en-GB'&$skip=3&$top=3"/> <entry> <id>https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/v1/Web?Q +uery='xbox'&Market='en-GB'&$skip=0&$top=1</id> <title type="text">WebResult</title> <updated>2013-03-13T19:01:31Z</updated> <content type="application/xml"> <m:properties> <d:ID m:type="Edm.Guid">13bfd262-8460-4487-827f-465643cb7</d:ID> <d:Title m:type="Edm.String">Xbox 360 - Xbox.com</d:Title> <d:Description m:type="Edm.String">Your ultimate Xbox 360 ....</d: +Description> <d:DisplayUrl m:type="Edm.String">www.xbox.com</d:DisplayUrl> <d:Url m:type="Edm.String">http://www.xbox.com/</d:Url> </m:properties> </content> </entry> <entry> <id>https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/v1/Web?Q +uery='xbox'&Market='en-GB'&$skip=1&$top=1</id> <title type="text">WebResult</title> <updated>2013-03-13T19:01:31Z</updated> <content type="application/xml"> <m:properties> <d:ID m:type="Edm.Guid">daf94bdf-e59b-4e17-8c06-62a8b4ff8</d:ID> <d:Title m:type="Edm.String">Xbox UK Home</d:Title> <d:Description m:type="Edm.String">For UK Xbox gamers ...</d:Descr +iption> <d:DisplayUrl m:type="Edm.String">www.xbox.com/GB</d:DisplayUrl> <d:Url m:type="Edm.String">http://www.xbox.com/GB</d:Url> </m:properties> </content> </entry> <entry> ... etc, etc, etc ..... </entry> </feed>

So, I'm trying to get the values of d:Title, d:Description, and d:Url, but seem to be having problems. I'm using XML::Simple, which I'm slightly more familiar with than anything else - but far from proficient.

So, I've got the data, like this:

$data   =$xml->XMLin($bingdata,ForceArray=>1);

... and then try to process each <entry>, as such:

foreach my $record (@{$data->{'feed:entry'}->[0]->{'content:m:properties'}})

... but it just skips the loop, because presumably I don't have the loop set up correctly.

I was hoping I could just loop through and do something like:

my $title=$record->{'d:Title'}->[0];, etc.

Very confused ... Any help would be much appreciated!

Thanks.

In reply to Parsing XML by DanielSpaniel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.