Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

[Help] How to extract values between xml tags responded by server?

delphi xml soundcloud

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1 rabirabi


    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 13 October 2013 - 04:41 AM

Hi again, Here I came across a problem when extracting the values between xml tags. Actually I am using soundcloud api. After querying a music name. The server responds data into xml format. I need to extract data like title, size, etc.


The probelm for me is that the response xml contains array data type. I googled but couldn't find enough response.


here is small piece of code of the response from server:


Full xml file : http://www.mediafire...g/SoundClou.xml

<?xml version="1.0" encoding="UTF-8"?>
    <id type="integer">73461631</id>
    <created-at type="datetime">2013-01-03T10:13:39Z</created-at>
    <user-id type="integer">24661622</user-id>
    <duration type="integer">323372</duration>
    <commentable type="boolean">true</commentable>
    <original-content-size type="integer">5181360</original-content-size>
    <streamable type="boolean">true</streamable>
    <downloadable type="boolean">false</downloadable>
    <purchase-url nil="true"></purchase-url>
    <label-id nil="true"></label-id>
    <purchase-title nil="true"></purchase-title>
    <title>Tum Se Hi - Jab We Met</title>
    <video-url nil="true"></video-url>
    <bpm nil="true"></bpm>
    <release-year nil="true"></release-year>
    <release-month nil="true"></release-month>
    <release-day nil="true"></release-day>
      <id type="integer">24661622</id>
      <username>Nitish Nayak Nie-30</username>
    <playback-count type="integer">5983</playback-count>
    <download-count type="integer">0</download-count>
    <favoritings-count type="integer">192</favoritings-count>
    <comment-count type="integer">14</comment-count>




#2 WingedPanther73


    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 14 October 2013 - 09:34 AM

I've written some fairly basic parsers in the past where you read one line at a time and use the pos() and copy() functions to extract data. Just read in the data one line at a time until you find the rows you need.

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/

#3 Luthfi


    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts

Posted 15 October 2013 - 02:59 AM

I am planning on writing xml tutorial. But since you might be in a hurry, I suggest you to read this one: Creating, Parsing and Manipulating XML Documents with Delphi. If you will work with that xml file heavily or/and you prefer to work closer in object oriented way, you could create classes for that xml file using Xml Mapper wizard (menu Tools -> XML Mapper).

#4 rabirabi


    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 17 October 2013 - 02:37 AM

Well I solved my problem using clXml i.e. Cleaver Internet Suite Component. But I am still not satisfied with using external library. I am still waiting for some tutorials from masters.


Here is the code(only sample):


uses clXmlUtils, MSXML;


procedure parsexml;
  dom: IXMLDomDocument;
 Rootnode,nodes,  anode, bnode, cnode: IXMLDOMNode;
  dom := CoDomDocument.create();
  dom.loadXML(WideString(response));  // response is the response xml text from server

 Rootnode := dom.selectSingleNode('tracks');
  for i := 0 to Rootnode.childNodes.length-1 do begin
        nodes := Rootnode.childNodes.item[i];
        anode := nodes.selectSingleNode('title');
        bnode := nodes.selectSingleNode('duration');
        cnode := nodes.selectSingleNode('uri');
        ListView1.Items.Item[i].Caption := GetNodeText(anode);
        ListView1.Items.Item[i].SubItems.Add(GetNodeText(cnode)) ;


Again, thanks for your time :)

#5 Luthfi


    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts

Posted 17 October 2013 - 08:56 AM

Ok, congrats on your finding. Using external library is fine, as long as you add little documentation on them to avoid possible confusion in the future. Add a comment or two will be fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download