【问题标题】:Adding only one subnode using xmlstarlet使用 xmlstarlet 只添加一个子节点
【发布时间】:2013-07-18 11:52:23
【问题描述】:

下达命令

xml ed -N x=http://java.sun.com/xml/ns/j2ee -s //x:web-app/x:security-constraint/x:auth-constraint -t elem -n role-name -v appuser WEB-INF/web.xml

但是上面的命令添加了两个名为appuser的子节点,因为我的xml中出现了两次“web-app/security-constraint/auth-constraint”。我只想添加一个。我该怎么做?

【问题讨论】:

  • 你能发布你的 web.xml 吗?
  • 有点像这样 role1role2role1-name>
  • 我只想在第一次出现时添加我的值

标签: xml xmlstarlet


【解决方案1】:

你可以让你的 xpath 只匹配第一个安全约束元素:

//x:web-app/x:security-constraint[1]/x:auth-constraint

【讨论】:

    猜你喜欢
    • 2019-09-11
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多