help in creating xml files.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help in creating xml files.
# 1  
Old 02-28-2010
Question help in creating xml files.

Hello,

I am a newbie to the xml world and need all your help in this.

I am trying to create a xml file by automatically reading the mp3 files in a directory. I am expecting that xml file to have all the mp3 files as below.

Code:
<xml>
    <track>
        <path>../Songs/titile/song1.mp3</path>
        <title>song1</title>
    </track>
    <track>
        <path>../Songs/titile/song2.mp3</path>
        <title>song2</title>
    </track>
</xml>

I read the following posting in the forum.
Code:
_url="http://www.servername.com/mp3s" export _url

find . -name '*.mp3' |
  while IFS= read -r; do
    _f="${REPLY#*/}"
    printf '<file>%s/%s</file>\n' "$_url" "$_f" > "${_f%.*}.xml"

(https://www.unix.com/shell-programmin...each-file.html)

How do I create that file? what type of editor/compiler do I need to create that file?

It will be a huge help if I get this done.

Thanks a lot in advance.

Regards,
Ramesh
done

Last edited by Scott; 02-28-2010 at 01:43 PM.. Reason: Please use code tags
# 2  
Old 02-28-2010
I was a bit bored and it might be good for me,
so...
you can specify files on command line or pipe them in as a list

ls | mp3xml.pl
mp3xml.pl *.mp3

obviously you will need perl and to download the XML::Twig and MP3::Info packages.
see your distro package management sytem.

Code:
#!/usr/bin/perl

use strict;
use warnings;
use XML::Twig;
use MP3::Info;


my @files = @ARGV? @ARGV : (<>);
chomp @files;

my $xml = XML::Twig->new(pretty_print => 'indented');
$xml->parse(q#<mp3_list/>#);

sub make_elements {

    my $H = get_mp3tag(shift);
    my @L;
    while (my ($k, $v) = each (%$H) ){
        push @L, my $elt = XML::Twig::Elt->new($k, $v);
    }
    return @L ;
}

foreach my $file (@files) {
    my $id = XML::Twig::Elt->new('id', make_elements($file));
    my $elt = XML::Twig::Elt->new('file', {name=>$file}, $id);

    $elt->paste('last_child', $xml->root);

}

$xml->flush;

Code:
$ ls | mp3xml.pl       
<mp3_list>
  <file name="01_N.W.O.mp3">
    <id>
      <YEAR>1992</YEAR>
      <ARTIST>Ministry</ARTIST>
      <COMMENT></COMMENT>
      <TITLE>N.W.O.</TITLE>
      <ALBUM>Psalm 69: The Way to Succeed &amp; the Way to Suck Eggs</ALBUM>
      <GENRE>Metal</GENRE>
      <TRACKNUM>1</TRACKNUM>
      <TAGVERSION>ID3v1.1 / ID3v2.3.0</TAGVERSION>
    </id>
  </file>
  <file name="02_Just_One_Fix.mp3">
    <id>
      <YEAR>1992</YEAR>
      <ARTIST>Ministry</ARTIST>
      <COMMENT></COMMENT>
      <TITLE>Just One Fix</TITLE>
      <ALBUM>Psalm 69: The Way to Succeed &amp; the Way to Suck Eggs</ALBUM>
      <GENRE>Metal</GENRE>
      <TRACKNUM>2</TRACKNUM>
      <TAGVERSION>ID3v1.1 / ID3v2.3.0</TAGVERSION>
    </id>

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

2. Shell Programming and Scripting

Splitting xml file into several xml files using perl

Hi Everyone, I'm new here and I was checking this old post: /shell-programming-and-scripting/180669-splitting-file-into-several-smaller-files-using-perl.html (cannot paste link because of lack of points) I need to do something like this but understand very little of perl. I also check... (4 Replies)
Discussion started by: mcosta
4 Replies

3. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

4. Shell Programming and Scripting

Creating multiple xml tag lines in a file

Hi All, Can someone tell me how can we create same xml tag lines based on the number of lines present in other file and replace the Name variable vaule present in other file. basically I have this xml line <typ:RequestKey NameType="RIC" Name="A1" Service="DDA"/> and say I... (4 Replies)
Discussion started by: Optimus81
4 Replies

5. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 Replies

6. Shell Programming and Scripting

Creating a larger .xml file from a template(sample file)

Dear All, I have a template xml file like below. ....Some---Header....... <SignalPreference> ... <SignalName>STRING</SignalName> ... </SignalPreference> ......Some formatting text....... <SignalPreference> ......... ... (3 Replies)
Discussion started by: ks_reddy
3 Replies

7. Shell Programming and Scripting

Need help creating a script to FTP files to a server and then delete the files that were transfered.

I am trying to FTP files to a Windows server through my Linux machine. I have setup the file transfer with no problems but am having problem deleting those files from the Linux box. My current non-working solution is below. Any ideas, anyone?? :wall: Please be gentle, I'm fairly new to this... (4 Replies)
Discussion started by: jmalfhs
4 Replies

8. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

9. Shell Programming and Scripting

Need help in creating a Unix Script to parse xml file

Hi All, My requirement is create an unix script to parse the xml file and display the values of the Elements/value between the tags on console. Like say, I would like to fetch the value of errorCode from the below xml which is 'U007' and display it. Can we use SED command for this? I have tried... (10 Replies)
Discussion started by: Anil.Wmg
10 Replies
Login or Register to Ask a Question