I'm trying to figure out how to insert a text in an xml file with sed command. I started to try some basic commands with sed :
sed -i -e ' <property name="prop1" ref="ANOTHER_BEAN" /> ' my_config_file.xml
it's adding this line but not in the position that I want
The problem for my specific case is that the text should be add to a certain position (certain bean as it's a java config file)
Example
<bean id="BEAN_ID_1"
class="com.toto.BeanClass1"
scope="prototype">
<property name="prop1" ref="ANOTHER_BEAN_1" />
<property name="prop2" ref="BEAN1" />
</bean>
<bean id="BEAN_ID_2"
class="com.toto.BeanClass2"
scope="prototype">
<property name="prop_1" ref="ANOTHER_BEAN_2" />
<property name="prop_2" ref="BEAN2" />
</bean>
I want to add this property to the bean named 'BEAN_ID_1' before the enclosing tag
<property name="property" ref="ANOTHER_BEANXXX" />
so the output will be :
<bean id="BEAN_ID_1"
class="com.toto.BeanClass1"
scope="prototype">
<property name="prop1" ref="ANOTHER_BEAN_1" />
<property name="prop2" ref="BEAN1" />
<property name="property" ref="ANOTHER_BEANXXX" />
</bean>
<bean id="BEAN_ID_2"
class="com.toto.BeanClass2"
scope="prototype">
<property name="prop_1" ref="ANOTHER_BEAN_2" />
<property name="prop_2" ref="BEAN2" />
</bean>
PS: I can't rely on line number since in production I have no Idea how is the file
Can anybody help me on this ? Thanks a lot