LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 08-08-2006, 07:42 PM   #1
wmh830621
LQ Newbie
 
Registered: Jul 2006
Posts: 7

Rep: Reputation: 0
Help!Write xml document with shell scripts


I have a xml document fixed structure.i need to write some information into the xml document.the xml document is following:
<?xml version="1.0" encoding="Shift-JIS"?>
<flash_cfg>
<server ip=" " port=" "/>
<language_url> </language_url>
<project_name>SADA</project_name>
</flash_cfg>
i need to write attribute of ip and port,for example:
<?xml version="1.0" encoding="Shift-JIS"?>
<flash_cfg>
<server ip="255.255.255.255" port="5555"/>
<language_url>/var/www/home</language_url>
<project_name>SADA</project_name>
</flash_cfg>
how to use shell scripts complete this function?
Need your help!
 
Old 08-10-2006, 04:13 AM   #2
nhydra
Member
 
Registered: May 2006
Distribution: Fedora Core, FreeSpire, PC-BSD, NetBSD
Posts: 96

Rep: Reputation: 15
How you would like to do that?
Shell scripts? Probably if you can use Perl will have better result and the program will be easier for programming.
 
Old 08-10-2006, 05:15 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
crude example, will modify and create .bak file

Code:
 perl -pi.bak -e 's|(<server ip=).*|$1"255.255.255.255" port="5555"/>|'
 
Old 08-10-2006, 09:22 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
hello wmh830621
you can try this concept of mine. just try to improve the code. i also haven't tested it yet cause i don't have any access to a terminal or console right now.

Code:
#!/bin/bash

# you can use read or VAR="$1" to setup these variables
SERVER_IP=
SERVER_PORT=
LANGUAGE_URL=
PROJECT_NAME=
OUTPUTFIL=

{
    echo "<?xml version=\"1.0\" encoding=\"Shift-JIS\"?>"
    echo "<flash_cfg>"
    echo "<server ip=\"${SERVER_IP}\" port=\"${SERVER_PORT}\"/>"
    echo "<language_url>${LANGUAGE_URL}</language_url>"
    echo "<project_name>${PROJECT_NAME}</project_name>"
    echo "</flash_cfg>"
} > ${OUTPUTFIL}
regards
konsolebox
 
Old 08-11-2006, 04:55 AM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
hello again wmh830621. i got your message from mail and i thought that i should frankly tell you that it will just take too long to discuss the code.

rather i'm suggesting that you read:
bash beginner's guide: http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
and then
advanced bash scripting howto http://www.tldp.org/LDP/abs/html/

please try them. they're just easy to understand. also take note more on variables, quoting and output redirection.

--------------------
ok i'll explain some

these are the variables
Code:
SERVER_IP=
SERVER_PORT=
LANGUAGE_URL=
PROJECT_NAME=
OUTPUTFIL=
the next commands are enclosed in braces to redirect their output to the file
Code:
{ 
   commands
} > FILE
so

Code:
{
    echo "<?xml version=\"1.0\" encoding=\"Shift-JIS\"?>"
    echo "<flash_cfg>"
    echo "<server ip=\"${SERVER_IP}\" port=\"${SERVER_PORT}\"/>"
    echo "<language_url>${LANGUAGE_URL}</language_url>"
    echo "<project_name>${PROJECT_NAME}</project_name>"
    echo "</flash_cfg>"
} > ${OUTPUTFIL}

Last edited by konsolebox; 08-11-2006 at 05:09 AM.
 
  


Reply



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
how to use shell scripts process xml document? wmh830621 Programming 4 08-03-2006 11:13 PM
rss/xml scripts for irc spooge Linux - Networking 0 02-26-2005 12:49 AM
Can't run shell scripts I write? JustinCoyan Slackware 2 08-06-2004 12:50 PM
PHP - XML error: junk after document element at line... jimieee Programming 2 04-27-2004 11:16 AM
Reading a xml document: amirspl Programming 3 09-10-2003 07:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:45 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration