LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-17-2008, 02:41 PM   #1
panoskan
LQ Newbie
 
Registered: Sep 2008
Posts: 10

Rep: Reputation: 0
help with complex bash script-XML handling


Hello

I need to write a script that will do the following:

The script will be called by an application while, at the same time, the application will create an xml file. After that, I want to process the xml file and derive only the text included by specific tags. Then, I want that text to be passed to another application that will make some automatic substitutions (this program can accept standard input or text files). After that, I want the changed text to return to its original position in the original xml.

This seems quite complex to me, but I would like some help with the logic and the steps I must follow. As I see it, I would have to assign the text I want to a global variable, which will then be passed to the 2nd application that will do the substitutions. Should I use a text editor (sth like sed maybe) to parse the xml and find the text? Are there any command line xml editors that will make the procedure easier?

Thanks in advance.

Panos
 
Old 09-17-2008, 03:05 PM   #2
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46
Moin,

I would prefer to use a command line tool which is specialised in parsing xml, like xmlcatalog of xmllint - or to use Perl with a xml module.

You will not be happy trying to parse xml with sed & Co.

Jan
 
Old 09-17-2008, 07:07 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Concur with above.
 
Old 09-18-2008, 04:10 PM   #4
panoskan
LQ Newbie
 
Registered: Sep 2008
Posts: 10

Original Poster
Rep: Reputation: 0
I am half way to accomplish it -- more help please

Hello,

You guys were absolutely right about using an xml command-line parser. After I gave up with grep, I found a fantastic program, xmlstarlet, that simplifies incredibly the task of extracting the text I want.

Now, I have found the way to put the modified text back to the xml file, but I need some advice about accessing the other application that will process it. The other application runs on another machine, my server, so I have to find a way to pass the text there and have it back modified to my desktop pc. One more challenge is that the remote program loads huge amount of data in memory when it is called, so I need that data to stay in memory otherwise the processing of the text is very time consuming. I was advised to use netpipes, hose and faucet, to establish a client-server communication. However, I can't find much documentation about this.

Any ideas are most welcome.

Thanks

Panos
 
Old 09-18-2008, 07:19 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Quote:
netpipes, hose and faucet,
never heard of that!
I think you (they) mean network (socket) programming, using the TCP protocol.
http://beej.us/guide/bgnet/ a guide in C.

Which lang are you comfortable with? Personally I use Perl, but most of the 'serious' langs have a socket lib or equiv.
 
  


Reply

Tags
bash, xml


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: handling of UTF-8 in XML and HTML jot Programming 5 07-26-2009 02:53 PM
Bash script to strip some content from XML file. musther Programming 10 10-14-2007 05:47 PM
LXer: PHP5's special XML parsing techniques for complex docs LXer Syndicated Linux News 0 03-08-2007 05:16 AM
Parse XML in bash script MikeyCarter Linux - Software 1 02-16-2007 01:19 PM
Bash Script and Loop error handling Kedelfor Programming 5 05-22-2005 02:22 PM


All times are GMT -5. The time now is 10:49 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration