How to add multiple lines to an existing xml file? Can we do thefollowing way?

W

wengao

xml ed -i <xpath> -t elem -n Value -v <value1> \
-t elem -n Value -v <value2> \
-t elem -n Value -v <value3> sample.xml


There was a complaint about the second one: I/O warning : failed to load
external entity "elem"

Any thoughts?

Thanks,
Wengao
 
H

Hermann Peifer

wengao said:
xml ed -i <xpath> -t elem -n Value -v <value1> \
-t elem -n Value -v <value2> \
-t elem -n Value -v <value3> sample.xml


There was a complaint about the second one: I/O warning : failed to load
external entity "elem"

Any thoughts?

Thanks,
Wengao

It looks like you have to repeat the full syntax, see below.

Hermann

$ cat table.xml # sample file from xmlstarlet manual

<?xml version="1.0"?>
<xml>
<table>
<rec id="1">
<numField>123</numField>
<stringField>String Value</stringField>
</rec>
<rec id="2">
<numField>346</numField>
<stringField>Text Value</stringField>
</rec>
<rec id="3">
<numField>-23</numField>
<stringField>stringValue</stringField>
</rec>
</table>
</xml>

$ xmlstarlet ed \
-i /xml/table/rec/numField -t elem -n Value -v value1 \
-i /xml/table/rec/numField -t elem -n Value -v value2 \
-i /xml/table/rec/numField -t elem -n Value -v value3 \
table.xml

<?xml version="1.0"?>
<xml>
<table>
<rec id="1">
<Value>value1</Value>
<Value>value2</Value>
<Value>value3</Value>
<numField>123</numField>
<stringField>String Value</stringField>
</rec>
<rec id="2">
<Value>value1</Value>
<Value>value2</Value>
<Value>value3</Value>
<numField>346</numField>
<stringField>Text Value</stringField>
</rec>
<rec id="3">
<Value>value1</Value>
<Value>value2</Value>
<Value>value3</Value>
<numField>-23</numField>
<stringField>stringValue</stringField>
</rec>
</table>
</xml>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top