使用sed删除名称空间前缀 [英] Remove namespace prefix with sed

查看:90
本文介绍了使用sed删除名称空间前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要转换这段xml:

<v1:table>
  <v1:tr>
    <v1:td>Apples</v1:td>
    <v1:td>Bananas</v1:td>
  </v1:tr>
</v1:table>

通过删除名称空间前缀(即v1)

进入以下内容,并使用 sed 获得以下内容:

into the following by removing the namespace prefixes (i.e. v1) and get the following by using sed:

<table>
  <tr>
    <td>Apples</td>
    <td>Bananas</td>
  </tr>
</table>

有可能吗?

编辑:我还想声明xml保留在文件中.

EDIT: I also want to state that the xml is kept in a file.

推荐答案

此sed适用于您的示例:

This sed works for your example:

sed -E 's~(</?)v1:~\1~g' file

<table>
  <tr>
    <td>Apples</td>
    <td>Bananas</td>
  </tr>
</table>

不过,请注意,sed不是解析HTML/XML的最佳工具.考虑使用HTML解析器.

However just a note that sed is not the best tool for parsing HTML/XML. Consider using HTML parsers.

这篇关于使用sed删除名称空间前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆