Insert a new subnode in a xml file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Insert a new subnode in a xml file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-18-2012
gautamshrm3 gautamshrm3 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 18 December 2012, 4:31 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Insert a new subnode in a xml file

Hi,
i have an xml file and i want to edit a new sub node in a file
like

Code:
val="<activity android:label="@string/app_name" android_name=".MainActivity1" android:launchMode="singleTask" android:screenOrientation="portrait"
               android:configChanges="keyboardHidden|orientation"><intent-filter><action android_name="android.intent.action.MAIN"/>
                 <category android_name="android.intent.category.LAUNCHER"/></intent-filter></activity>"

i am using this command

Code:
xmlstarlet ed --subnode "/manifest/application" --type elem -n "$val" -v "" AndroidManifest.xml > and.xml


command running fine but new generated xml file is wroung because it add some more tag like :-

Code:
<<activity xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" 
           android_name=".MainActivity1" android:launchMode="singleTask" android:screenOrientation="portrait" 
          android:configChanges="keyboardHidden|orientation"> <intent-filter> <action android_name="android.intent.action.MAIN"/> 
         <category android_name="android.intent.category.LAUNCHER"/> 
     </intent-filter> </activity>></<activity xmlns:android="http://schemas.android.com/apk/res/android" 
        android:label="@string/app_name" android_name=".MainActivity1" android:launchMode="singleTask" android:screenOrientation="portrait" 
       android:configChanges="keyboardHidden|orientation"> <intent-filter> <action android_name="android.intent.action.MAIN"/> 
       <category android_name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>>


how can i edit this. pls help me

Last edited by jim mcnamara; 12-18-2012 at 12:02 PM.. Reason: Please use code tags for data and code samples jmc - readability
Sponsored Links
    #2  
Old 12-18-2012
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 4 April 2014, 4:57 PM EDT
Location: Southern NJ, USA (Nord)
Posts: 4,359
Thanks: 8
Thanked 534 Times in 513 Posts
Well, it made a mess of it! You have two of the original, probably one from the file and one from $val, and some <> ! XML is not that hard to edit by hand, if you know what you want to add. I recommend indenting and linefeeds to make the structure easy to see.

Last edited by DGPickett; 12-18-2012 at 04:59 PM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Insert a new line between the XML tags?. laknar Shell Programming and Scripting 3 11-25-2012 03:24 PM
Insert value of env variable in xml file jakSun8 Shell Programming and Scripting 2 10-15-2012 10:19 AM
Help required in Splitting a xml file into multiple and appending it in another .xml file ganesan kulasek Shell Programming and Scripting 4 07-26-2012 01:22 PM
How to add the multiple lines of xml tags before a particular xml tag in a file mjavalkar Shell Programming and Scripting 0 06-25-2012 04:54 PM
script to run shell command and insert results to existing xml file littlejon Shell Programming and Scripting 5 08-12-2005 04:59 PM



All times are GMT -4. The time now is 12:30 PM.