Actualizar parámetro XML, con espacio de nombres, usando xmlstarlet

Actualizar parámetro XML, con espacio de nombres, usando xmlstarlet

Tengo este archivo XML:

<?xml version="1.0" encoding="UTF-8" ?>
<engineConfiguration xmlns="http://bla.com/engine/management/engineConfiguration">
    <engineParameter>
        <name>PORT_ID</name>
        <value>47827</value>
    </engineParameter>
    <engineParameter>
        <name>POS_PRINTER_PORT_ID</name>
        <value>27001</value>
    </engineParameter>
    <engineParameter>
        <name>PDS_WS_LOCATION</name>
        <value>http://localhost:8080/pds-jbrain-ws/pdsservice?wsdl</value>
    </engineParameter>
</engineConfiguration>

Estoy intentando actualizar el POS_PRINTER_PORT_IDvalor, pero me cuesta hacerlo bien.

Probé los siguientes comandos:

xmlstarlet ed -u '/engineConfiguration/engineParameter/POS_PRINTER_PORT_ID' -v 9999 engineConfiguration.xml
xmlstarlet ed -N s=http://bla.com/engine/management/engineConfiguration -u '/s:engineConfiguration/s:engineParameter[name = "POS_PRINTER_PORT_ID"]/value' -v 999 engineConfiguration.xml

También lo estaba intentando, xmllintpero leí que ese xmlstarletes el camino a seguir.

Respuesta1

Su último intento es casi correcto, pero olvidó agregar el espacio de nombres a los nodos namey :value

xmlstarlet ed \
    -N s=http://bla.com/engine/management/engineConfiguration \
    -u '/s:engineConfiguration/s:engineParameter[s:name = "POS_PRINTER_PORT_ID"]/s:value' \
    -v 9999 file.xml

O usar parámetros importados desde la línea de comando en lugar de valores codificados en las expresiones:

xmlstarlet ed \
    -N s='http://bla.com/engine/management/engineConfiguration' \
    --var n "'POS_PRINTER_PORT_ID'" --var v "'9999'" \
    -u '/s:engineConfiguration/s:engineParameter[s:name = $n]/s:value' \
    -x '$v' file.xml

Usandoxq:

xq -x '( .engineConfiguration.engineParameter[] | 
         select(.name == "POS_PRINTER_PORT_ID").value ) |= 9999' file.xml

Con parámetros:

xq --arg n 'POS_PRINTER_PORT_ID' --arg v 9999 \
    -x '( .engineConfiguration.engineParameter[] | 
          select(.name == $n).value ) |= $v' file.xml

información relacionada