Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用xmlstarlet搜索和编辑与条件匹配的xml标记_Xml_Substring_Xmlstarlet - Fatal编程技术网

如何使用xmlstarlet搜索和编辑与条件匹配的xml标记

如何使用xmlstarlet搜索和编辑与条件匹配的xml标记,xml,substring,xmlstarlet,Xml,Substring,Xmlstarlet,我需要一个解决方案,使用xmlstarlet根据条件搜索xmltag并编辑其xmltag值 我的命令 xmlstarlet ed -N a="http://maven.apache.org/POM/4.0.0" -u "/a:project/a:properties/a:ifm.core_system_ui.version[.=contains(.,'3.700.999')]" -x "concat(translate(substring-before(.,','),'8','7'),',',s

我需要一个解决方案,使用xmlstarlet根据条件搜索xmltag并编辑其xmltag值

我的命令

xmlstarlet ed -N a="http://maven.apache.org/POM/4.0.0" -u "/a:project/a:properties/a:ifm.core_system_ui.version[.=contains(.,'3.700.999')]" -x "concat(translate(substring-before(.,','),'8','7'),',',substring-after(.,','))" pom.xml
我已经创建了xmlstarlet命令来搜索和替换
/properties/ifm.core\u system\u ui.version
下的xmltag值,但是我需要我们的社区帮助来开发此命令,以便在
下搜索名称以
version>
结尾的xmltag,并编辑该标记下的值

示例pom.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">
<properties>
        <ifm.core_system_ui.version>[3.800.0, 3.800.999)</ifm.core_system_ui.version>
        <ifm.fault_ui.version>[3.800.0, 3.800.999)</ifm.fault_ui.version>
        <ifm.ifm_admin_ui.version>[3.800.0, 3.800.999)</ifm.ifm_admin_ui.version>
        <ifm.ifm_grouping_ui.version>(3.800.0, 3.800.999)</ifm.ifm_grouping_ui.version>
        <ifm.ifm_config_archive_ui.version>(3.800.0, 3.800.999)</ifm.ifm_config_archive_ui.version>
        <xmp_nbi_static_content.version>(17.1.8, 18.1.999)</xmp_nbi_static_content.version>
        <helpdesk_ui.version>[3.95.0,3.95.999)</helpdesk_ui.version>
        <someother>[7.77.0,8.88.888)<someother>
</properties>
</project>

[3.800.0, 3.800.999)
[3.800.0, 3.800.999)
[3.800.0, 3.800.999)
(3.800.0, 3.800.999)
(3.800.0, 3.800.999)
(17.1.8, 18.1.999)
[3.95.0,3.95.999)
[7.77.0,8.88.888)
期望

<?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">
<properties>
        <ifm.core_system_ui.version>[3.700.0, 3.800.999)</ifm.core_system_ui.version>
        <ifm.fault_ui.version>[3.700.0, 3.800.999)</ifm.fault_ui.version>
        <ifm.ifm_admin_ui.version>[3.700.0, 3.800.999)</ifm.ifm_admin_ui.version>
        <ifm.ifm_grouping_ui.version>(3.700.0, 3.800.999)</ifm.ifm_grouping_ui.version>
        <ifm.ifm_config_archive_ui.version>(3.700.0, 3.800.999)</ifm.ifm_config_archive_ui.version>
        <xmp_nbi_static_content.version>(17.1.8, 18.1.999)</xmp_nbi_static_content.version>
        <helpdesk_ui.version>[3.95.0,3.95.999)</helpdesk_ui.version>
        <someother>[7.77.0,8.88.888)<someother>
</properties>
</project>

[3.700.0, 3.800.999)
[3.700.0, 3.800.999)
[3.700.0, 3.800.999)
(3.700.0, 3.800.999)
(3.700.0, 3.800.999)
(17.1.8, 18.1.999)
[3.95.0,3.95.999)
[7.77.0,8.88.888)

由于xmlstarlet无法使用XPath 2.0函数
ends-with()
,因此可以尝试使用
substring()
检查名称的结尾

尝试替换:

a:ifm.core_system_ui.version
与:

这是更新的命令(未测试)

*[substring(name(),string-length(name())-string-length('version')+1)='version']
xmlstarlet ed -N a="http://maven.apache.org/POM/4.0.0" -u "/a:project/a:properties/*[substring(name(),string-length(name())-string-length('version')+1)='version'][.=contains(.,'3.700.999')]" -x "concat(translate(substring-before(.,','),'8','7'),',',substring-after(.,','))" pom.xml