sed and XML


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed and XML
# 1  
Old 12-31-2009
sed and XML

I am trying to edit an XML file with sed, and I can successfully do so, but the resulting file no longer opens as an XML file?

I am working on a project to automate DVD authoring. I am using DVD Studio Pro, which uses XML files as its instructions for DVD authoring. I've worked out a substitution which makes menus, buttons and tracks etc... I've successfully done the XML substitution in a program called pList Edit Pro, but when I try and do the same substitution with sed the resulting file doesn't work in studio pro and won't open with pList Edit Pro any longer...

Any Help would be greatly appreciated,
-Starcast

my script looks like this

Code:
#!/bin/bash

#Edit an XML file based on parsed M2V and AC3 files for DVD Studio Pro Automated Authoring

echo "Enter the project name & press ENTER, then enter the M2V & AC3 filename & press ENTER"
read projectname
read filename

echo " "
echo "++ Project: $projectname"
echo " "
echo "++ File: $filename"
echo " "

#get the ObjectDataB template

cd /Volumes/Video4/AADVDA/Insert-Files-Here/ASTOUNDDVDPROJECT.dspproj/Contents/Resources/
cp ObjectDataB /Volumes/Video4/AADVDA/WORKING/
cd /Volumes/Video4/AADVDA/WORKING/

#do subsutution and clean up extra files

sed 's/DVD_TEMPLATE_SLUG/$filename/g' ObjectDataB > ObjectDataBy
rm ObjectDataB
sed 's/ASTOUNDDVDPROJECT/$projectname/g' ObjectDataBy > ObjectDataB
rm ObjectDataBy

#Remove original ObjectDataB from final project file

cd /Volumes/Video4/AADVDA/Insert-Files-Here/$projectname.dspproj/Contents/Resources/
rm ObjectDataB

#put the subsutituted ObjectDataB file in the final project file

cd /Volumes/Video4/AADVDA/WORKING/
cp ObjectDataB /Volumes/Video4/AADVDA/Insert-Files-Here/$projectname.dspproj/Contents/Resources/

#Remove leftover file

rm ObjectDataB

#run burn applescript

cd /Volumes/Video4/AADVDA/SCRIPTS/
./bapp.app

exit



---------- Post updated at 09:01 AM ---------- Previous update was at 08:27 AM ----------

Here is an error message from pList Edit Pro when I try to open the substituted file...

Quote:
There was an error reading the property list file (The file /Volumes/Video4/AADVDA/Test/ObjectDataBx could not be opened because an error occurred parsing the file.
Conversion of string failed. The string is empty.).
Would you like to open the raw text of the file instead?
# 2  
Old 12-31-2009
Quote:
Originally Posted by Starcast
I am trying to edit an XML file with sed, and I can successfully do so, but the resulting file no longer opens as an XML file?

Did you look at the resulting file? Did you do a diff to compare them?
Quote:
Code:
sed 's/DVD_TEMPLATE_SLUG/$filename/g' ObjectDataB > ObjectDataBy
rm ObjectDataB
sed 's/ASTOUNDDVDPROJECT/$projectname/g' ObjectDataBy > ObjectDataB
rm ObjectDataBy


Variables are not expanded inside single quotes.

Code:
sed "s/DVD_TEMPLATE_SLUG/$filename/g" ObjectDataB > ObjectDataBy

sed "s/ASTOUNDDVDPROJECT/$projectname/g" ObjectDataBy > ObjectDataB

# 3  
Old 12-31-2009
When dealing with XML files, I feel that it should not be edited/modified as a stream of characters in-place, but edit it as an individual node in a tree ( either DOM or native structure ) doing so, its straight forward, still scalable even if the XML tree becomes more complex and all the more making changes is not difficult.

Try XML editing modules like Twig
XML::Twig - search.cpan.org
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bit of sed help in XML

Hi all, need some help seeing the bug in my SED Source XML <SMART_FOLDER JOBISN="1" SUB_APPLICATION="PMT-APB" MEMNAME="Job0" JOBNAME="PMT-APB" FOLDER_NAME="PMT-APB"> </SMART_FOLDER> My SED Command sed -e 's/\(<SMART_FOLDER \)\(.*FOLDER_NAME="PMT-APB"\)/\FOLDER_ORDER_METHOD="PCI" \2/' <... (0 Replies)
Discussion started by: J-Man
0 Replies

2. Shell Programming and Scripting

sed extract from xml

I have an xml file that generally looks like this: "<row><dnorpattern>02788920</dnorpattern><description/></row><row><dnorpattern>\+ 44146322XXXX</dnorpattern><description/></row><row><dnorpattern>40XXX</dnorpattern><description/></row><row><dnorpattern>11</dn... (4 Replies)
Discussion started by: garboon
4 Replies

3. Shell Programming and Scripting

Again, Sed and Xml

Hi all, I have a xml file like below, <JavaArgs> <containerSet> <container id="333"> <JavaArgs> Very Big String </Javargs> </container> <container id="334"> ... (5 Replies)
Discussion started by: nasbtv
5 Replies

4. Shell Programming and Scripting

SED extract XML value

I have the following string: <min-pool-size>2</min-pool-size> When I pipe the string into the following code I am expcting for it to return just the value "2", but its just reurning the whole string. Why?? sed -n '/<min-pool-size>/,/<\/min-pool-size>/p' Outputting:... (13 Replies)
Discussion started by: ArterialTool
13 Replies

5. Shell Programming and Scripting

modifying xml files using sed

Hello, I have lots of xml files in the same format and I need to modify a xml tag in these files. i loop over the files and apply sed to the files to make the modification but CPU goes to %100 while doing this. I think I'm doing something wrong. Here is my onliner: for f in $( find . -name... (1 Reply)
Discussion started by: xyzt
1 Replies

6. Shell Programming and Scripting

sed xml challenge

I have a web xml file that looks like this: <allinfo> <info> <a>Name1<\a> <b>address1<\b> <c>phone1<c> <\info> <info> <a>Name2<\a> <b>address2<\b> <c>phone2<c> <\info> <\allinfo> I want to use sed to... (2 Replies)
Discussion started by: katrvu
2 Replies

7. Shell Programming and Scripting

replace string in XML with sed

Greetings, I have an XML : file.xml <component> <name>abcd</name> <value>1234</value> </component> I am using sed to replace abcd with the desired value dynamically without knowing the actual value. sed 's/<name>./]\{1,\}<\/name>/<name>ijkl<\/name>/' file.xml > newfile.xml I... (6 Replies)
Discussion started by: chiru_h
6 Replies

8. Shell Programming and Scripting

SED for XML's

Hi My xml has element like below <BOOK>:</BOOK> If i wanna replace ":</BOOK>" with ": </BOOK>" i.e 3 spaces added. what should be the search pattern? I tried with "?:\<\/BOOK\>", but its not working in SED. Can someone suggest what would be the search patter looks like ? Thanks (1 Reply)
Discussion started by: braindrain
1 Replies

9. Shell Programming and Scripting

using sed with xml files part 2

I'm trying to replace a date in an XML file that has the format mm/dd/yyyy. I'm using the Unix date function to set up a variable with the current date but, when I try to replace the value in the XML file, the error message says it cannot be parsed. Here is the command I'm using ... (2 Replies)
Discussion started by: stonemonolith
2 Replies

10. Shell Programming and Scripting

using sed with xml files

Hello I'm working on a project modifying XML files in Unix and, I would like to use sed to change these values. For example, I've got a tag <book>354678209<\book> and I want to replace the value 354678209 with a another value without having to go into the file and change it manually. How can I do... (3 Replies)
Discussion started by: stonemonolith
3 Replies
Login or Register to Ask a Question