0

I have an XML file which looks like so:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Solr managed schema - automatically generated - DO NOT EDIT -->
    <schema name="default-config" version="1.6">
      <uniqueKey>id</uniqueKey>
     ....

I would like to insert this line:

<similarity class="solr.BM25SimilarityFactory"/>

between <schema.. and <uniqueKey like so:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Solr managed schema - automatically generated - DO NOT EDIT -->
    <schema name="default-config" version="1.6">
    <similarity class="solr.BM25SimilarityFactory"/>
      <uniqueKey>id</uniqueKey>

I am trying to do this using xmlstarlet, but not having much luck :(

1 Answer 1

2

Use two steps (I fold line for readability)

xmlstarlet ed -s "//schema" -t elem -n "similarity"  \
              -i "//similarity" -t attr -n "class" -v "solr.BM25SimilarityFactory"  \
 > final.xml

note the use of -s (subnode).

note also that line was added at the end, but it should be no problem for xmlparser.

You may wish to look at this stack overflow question.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .