-1

これが最初の xml ファイル input.xml です。

input.xml :

<Mapping>
        <Common>
            <Apps>
                <App ID = "id1">
                <config key = "Format" value = "PDF"/>
                </App>
                <App ID = "id2">
                <config key = "Logging" value = "no"/>
                <config key = "ExtraLogging" value = "no"/>
                </App>
            </Apps>

            <All>
            <config key="log1" value="N"/>
            </All>
        </Common>
</Mapping>

input.xml から読み取り、output.xml のそれぞれのエントリを追加/削除/更新する必要があります。

output.xml:

    <Mapping>
            <Common>
                <Apps>
                    <App ID = "id1">
                    <config key = "Format" value = "DOC"/>
                    </App>
                    <App ID = "id2">
                    <config key = "Logging" value = "yes"/>
                    </App>
                </Apps>

                <All>
                <config key="log1" value="N"/>
                </All>
            </Common>
    </Mapping>
4

1 に答える 1

1

あなたを使っxmlstarletて書くだろう

xmlstarlet ed \
    -u '//App[@ID="id1"]/config[@key="Format"]/@value' -v "DOC" \
    -u '//App[@ID="id2"]/config[@key="Logging"]/@value' -v "yes" \
    -d '//App[@ID="id2"]/config[@key="ExtraLogging"]' \
        input.xml > output.xml
于 2015-11-23T14:31:13.500 に答える