Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Beginner needs help getting a veriable from xml  (Read 3603 times)

0 Members and 1 Guest are viewing this topic.

Renfield

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Mac OS
    Beginner needs help getting a veriable from xml
    « on: December 19, 2011, 05:50:34 PM »
    Hello.  I'm new to *ix and am trying to pull a variable or two from an xml document.  The document is in the format:

    Code: [Select]
    <name>7_3(A).mov</name>
          <description>Some description from a file</description>
          <updatename>7_3_A.mov</updatename>
          <updatepath>Dailies Released</updatepath>
          <playlist>Selects Day 5,Dailies Day 5</playlist>
    What I need to do is take the value or values from inside the <playlist> tags and assign them to variables.  So, for this example, I'd like to be able to set $playlist1 to "Selects Day 5" and $playlist2 to "Dailies Day 5."  The values in that xml tag will always be comma separated and there can be any number of them.  I used grep to find the playlist lines, but I'm not sure what option is best to pipe grep's output to or how to assign it's output to variables.

    There are many more lines for each item described in the xml and there will be other instances of the <playlist> tag.  I'll need to ignore instances of any value already set so, for example, once I've got the values "Selects Day 5" and "Dailies Day 5" from the above example I will need to ignore any further instances of those values until the script is executed again.

    Any help would really be appreciated.

    Thanks!

    Dan

    Rob Pomeroy



      Prodigy

    • Systems Architect
    • Thanked: 124
      • Me
    • Experience: Expert
    • OS: Other
    Re: Beginner needs help getting a veriable from xml
    « Reply #1 on: December 20, 2011, 09:58:11 AM »
    Dan,

    If it were me, I'd haul the XML file in with a PHP script and use regular expressions to parse out the necessary information.  If you don't want to do this in your favourite scripting language, you could try getting the hang of awk, which is very good at this kind of job.

    Code: [Select]
    man awk
    or, preferably,

    Code: [Select]
    info awk
    (where available), for more details.

    awk is reasonably simple to learn initially, especially if you're already familiar with regex, but a bit of a swine to master.
    Only able to visit the forums sporadically, sorry.

    Geek & Dummy - honest news, reviews and howtos