linux - Convert xml containing only specific tags -


i have xml structure, , want convert xml one, fields. how can directly xmllint or similar tool? know can type of job php library parse xml want avoid that, if possible.

<?xml version="1.0" encoding="utf-8"?> <data>     <entities>        <ent_id>1</ent_id>        <name>john</name>        <age>15</age>     </entities>     <entities>        <ent_id>2</ent_id>        <name>pedro</name>        <age>20</age>     </entities> </data> 

to:

<?xml version="1.0" encoding="utf-8"?> <data>     <entities>        <name>john</name>     </entities>     <entities>        <name>pedro</name>     </entities> </data> 

i'd use xmlstarlet:

xmlstarlet ed -d '/data/entities/*[not(self::name)]' filename.xml 

xmlstarlet ed -d xpath deletes nodes input xml fit xpath expression, in case describes subnodes of /data/entities nodes not name nodes.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -