用文件中的内容附加xml标记

用文件中的内容附加xml标记,xml,xmlstarlet,Xml,Xmlstarlet,xmlstarlet-从文件中追加值会导致奇怪的问题 test.xml <?xml version="1.0"?> <config xmlns:foo="http://www.example.org/" xmlns:bar="http://www.example.org"> <actors> <actor id="1">Christian Bale</actor> <actor id="2"

xmlstarlet-从文件中追加值会导致奇怪的问题

test.xml

<?xml version="1.0"?>
<config xmlns:foo="http://www.example.org/" xmlns:bar="http://www.example.org">
    <actors>
        <actor id="1">Christian Bale</actor>
        <actor id="2">Liam Neeson</actor>
        <actor id="3">Michael Caine</actor>
    </actors>
    <foo:singers>
        <foo:singer id="4">Tom Waits</foo:singer>
        <foo:singer id="5">B.B. King</foo:singer>
        <foo:singer id="6">Ray Charles</foo:singer>
    </foo:singers>
</config>

克里斯蒂安·贝尔
利亚姆·尼森
迈克尔·凯恩
汤姆等着
B.B.金
雷·查尔斯
append.txt

<mint>
    <enabled>true</enabled>
    <cronExp>0 0 /5 * * ?</cronExp>
    <syncDeletes>true</syncDeletes>
    <syncProperties>true</syncProperties>
    <repoKey>example</repoKey>
    <url>https:// example.com/bar</url>
    <socketTimeoutMillis>15000</socketTimeoutMillis>
    <enableEventReplication>true</enableEventReplication>
    <syncStatistics>false</syncStatistics>
</mint>

真的
0 0 /5 * * ?
真的
真的
例子
https://example.com/bar
15000
真的
假的
我想在
/config/foo:singers

审判-

  • xmled-a/config/foo:singers-t text-n mints-v$(cat append.txt)test.xml
    - 未能加载外部实体“true”

  • xmled-a/config/foo:singers-t text-n mints-v“$(cat append.txt)”test.xml

    • 这确实会替换内容,但会添加实体字符,如
      <
      >

  • 从文件中为标签添加内容的正确方法是什么?

    对于在这里偶然发现的其他人,这对我很有用->

    xml ed -a /config/foo:singers -t text -n mints -v "$(cat append.txt)" test.xml | xmlstarlet unesc | xml fo
    
    xmlstarlet-unesc
    很重要-

    “xmlstarlet-unesc”在您的情况下是可以的。但如果有像&;在xml中的其他地方,“xmsltart unesc”将影响这些实体。我所做的就是使用xmlstarlet在我想要创建新节点的位置插入一个令牌。然后首先使用sed:sed-i'/token/r append.xml'test.xml将节点插入到标记后面的中间位置,然后删除标记:sed-i's/token$/'test.xml如果有更好的解决方案,我很乐意听到