与XPath一起使用时,如何在xmlstarlet更新命令中正确添加xml名称空间

时间:2019-08-05 17:09:50

标签: xml xmlstarlet

我的xmlstarlet命令出了什么问题? 如果以下约束在父元素下为真,我将尝试更新pom.xml的version元素
groupId == com.cisco.aems 和
版本== 3.700.11-SNAPSHOT

xml名称空间的概念使我对xmlstarlet语法的理解更加复杂,在解决xmlstarlet问题方面的任何帮助将不胜感激。 谢谢:-)

我尝试了以下命令的变体

<div class="modal inmodal" id="ModalNuevoRegistroUsuario" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" style="width : 1200px">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cerrar</span></button>
                <i class="fa fa-pencil-square-o modal-icon"></i>
                <h4 class="modal-title">Registrar Nuevo Usuario</h4>
                <small class="font-bold">Para registrarse recuerde llenar toda la información solicitada.</small>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                            <h3 class="panel-title">Registrarse en SAMI</h3>
                        </div>
                        <div class="panel-body">
                            <div class="panel-heading"><h3 class="panel-title">Información Ips</h3></div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group" style="align-self:center" id="formNuevoRegistroUsuario">
                                <div class="panel-body">
                                    <div class="row panelPadding">
                                        <div class="m-t-30">
                                            <div class="form-group col-md-10">
                                                <label class="control-label col-md-5">Ingrese el número de NIT de su IPS</label>
                                                <div class="input-group">
                                                    <input type="text" name="Nit" id="Nit" class="form-control" placeholder="mínimo 4 caracteres" />
                                                    <span class="input-group-btn">
                                                        <button class="btn btn-primary m-b-none" type="button" id="buscarIps" data-toggle="tooltip" data-placement="top" title=""><i class="fa fa-search"></i></button>
                                                    </span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <br />
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="ibox float-e-margins">
                                                <div class="panel panel-primary">
                                                    <div class="panel-heading">
                                                        <h3 class="panel-title ">Sedes de la IPS</h3>
                                                    </div>
                                                    <div class="panel-body">
                                                        <table class="table table-striped table-bordered table-hover dataTables-example table-se" id="dataTableIps" style="width:100%;">
                                                            <thead>
                                                                <tr>
                                                                    <th>Id</th>
                                                                    <th>Código prestador</th>
                                                                    <th>Nombre de la sede</th>
                                                                    <th>Sede</th>
                                                                    <th>Ciudad</th>
                                                                    <th>Departamento</th>
                                                                    <th>Telefono</th>
                                                                    <th>Email</th>
                                                                    <th>Opciones</th>
                                                                </tr>
                                                            </thead>
                                                            <tfoot>
                                                                <tr>
                                                                    <th>Id</th>
                                                                    <th>Código prestador</th>
                                                                    <th>Nombre de la sede</th>
                                                                    <th>Sede</th>
                                                                    <th>Ciudad</th>
                                                                    <th>Departamento</th>
                                                                    <th>Telefono</th>
                                                                    <th>Email</th>
                                                                    <th>Opciones</th>
                                                                </tr>
                                                            </tfoot>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-primary" id="btnModalAgregarSede" title="">  Agregar Sede </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="btnModalRegistroIpsEnSAMI"> Registrar IPS </button> |
                <button type="button" class="btn btn-default btn-outline" id="cancelarRegistroUsuario" data-dismiss="modal">Cerrar</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade inmodal" id="ModalEmail" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cerrar</span></button>
                <i class="fa fa-pencil-square-o modal-icon"></i>
                <h4 class="modal-title">Registrar Nuevo Usuario</h4>
                <small class="font-bold">Para registrarse recuerde llenar toda la información solicitada.</small>
            </div>
            <div class="modal-body">
                <form id="form">
                    <div class="columns">
                        <div class="form-group col-10">
                            <label class="control-label col-md-5">Ingrese su correo. </label>
                            <div class="input-group" id="email">
                                <input type="text" id="TextEmail" class="form-control"  autocomplete="off" style="width: 150%;">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                @Html.CustomButton("BtnSolicitarUser", "btn btn-primary multi", "button", "Solicitar")
                <button type="button" class="btn btn-default btn-outline cerrarmodalpdf" data-toggle="tooltip">Cerrar</button>
            </div>
        </div>
    </div>
</div>

我得到一个无效的表达式错误或什么也没有,但是我没有得到预期的结果

pom.xml示例

xmlstarlet ed -N a="http://maven.apache.org/POM/4.0.0" -u "/a:groupId[.='com.cisco.aems' and following
-sibling::version[1] = '3.700.11-SNAPSHOT']/a:following-sibling::version[1]" -x "concat(.,'-done')" pom_sandbox_nam.xml

预期

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>avc-utils</artifactId>
  <parent>
    <groupId>com.cisco.aems</groupId>
    <artifactId>aems_parent_pom</artifactId>
    <version>3.700.11-SNAPSHOT</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>
</project>

实际结果

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>avc-utils</artifactId>
  <parent>
    <groupId>com.cisco.aems</groupId>
    <artifactId>aems_parent_pom</artifactId>
    <version>3.700.11-SNAPSHOT-done</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>
</project>

1 个答案:

答案 0 :(得分:0)

使用以下命令:

xmlstarlet ed -N a="http://maven.apache.org/POM/4.0.0" -u "/a:project/a:parent/a:groupId[.='com.cisco.aems' and following-sibling::a:version[1] = '3.700.11-SNAPSHOT']/following-sibling::a:version[1]" -x "concat(.,'-done')" pom_sandbox_nam.xml

它产生以下XML:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>avc-utils</artifactId>
  <parent>
    <groupId>com.cisco.aems</groupId>
    <artifactId>aems_parent_pom</artifactId>
    <version>3.700.11-SNAPSHOT-done</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>
</project>

您错过了指定要更改的元素的整个路径,而没有指定适当的名称空间。