gpt4 book ai didi

xml - 在 bash 脚本中访问 xml 属性

转载 作者:太空宇宙 更新时间:2023-11-04 11:22:25 24 4
gpt4 key购买 nike

我需要从 bash 脚本中的 xml 文件获取属性,但我既不能使用 xmllint --xpath 也不能使用 xmlstarlet,因为它们在我工作的服务器上不可用。

我尝试过使用 grep、cut 和 sed 解决方案,但很长一段时间以来这都不是一个好的解决方案。

机器上有可用的 grep_xml,我可以用它访问元素,但是当我尝试访问我的属性时,我得到“处理程序中出现无法识别的错误表达式”

这是我的xml文件

<?xml version="1.0" standalone="yes"?>
<p4codeline xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="p4codeline_1_1.xsd">
<module name="kpreader" currentVersion="kpreader_1.1STD0" previousVersion="kpreader_1.0STD0">
<codeline owner="undefined" path="//HEP/jcas/kpreader/trunk/...">
<namingConvention/>
<description>Main codeline for development</description>
<rules>
<rule>Develop on MAIN, and create a TAG codeline on release</rule>
<rule>Never broke the build on the MAIN</rule>
</rules>
</codeline>
<externals>
<external viewPath="J2ep_BuildTools/..." codeLine="//CT/JAVA/J2ep_BuildTools/Source/tags/J2EP_BUILDTOOLS_1.6STD0/..." depotPath="."/>
</externals>
</module>
</p4codeline>

而且我只需要使用基于 bash 或命令的解决方案来访问代码行中的路径属性。

我试过类似的东西

xml_grep -t '/p4codeline/module/codeline/@path' file.xml

它回答我

error: unrecognized expression in handler: '/p4codeline/module/codeline@path' at /usr/bin/xml_grep line 183

最佳答案

通常情况下,此命令高度依赖于您的输入

$ awk '/path/ {print $4}' FS='"' file.xml
//HEP/jcas/kpreader/trunk/...

关于xml - 在 bash 脚本中访问 xml 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17316266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com