首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用sed只替换具有给定属性值的父元素中的命名空间。

使用sed只替换具有给定属性值的父元素中的命名空间。
EN

Unix & Linux用户
提问于 2015-05-14 15:08:02
回答 1查看 946关注 0票数 0

我希望使用sed替换xml文件中的命名空间(我已经放弃了尝试从ant (需要它的地方)进行命名空间的尝试)。主要问题是,有一个重复的元素列表-并不是所有的元素都需要替换。

Xml文件:

代码语言:javascript
复制
<xml-fragment>
  <imp:exportedItemInfo instanceId="WikiDS_v1_PS" typeId="ProxyService" xmlns:imp="http://www.bea.com/wli/config/importexport">
    <imp:properties>
      <imp:property name="dataclass" value="com.bea.wli.sb.resources.config.impl.XmlEntryDocumentImpl"/>
      <imp:property name="isencrypted" value="false"/>
    </imp:properties>
  </imp:exportedItemInfo>
  <imp:exportedItemInfo instanceId="NonShared/wikitest/FileUploadManagementDS_v1_BS_WSDL" typeId="WSDL" xmlns:imp="http://www.bea.com/wli/config/importexport">
    <imp:properties>
      <imp:property name="dataclass" value="com.bea.wli.sb.resources.config.impl.WsdlEntryDocumentImpl"/>
      <imp:property name="isencrypted" value="false"/>
    </imp:properties>
  </imp:exportedItemInfo>
  <imp:exportedItemInfo instanceId="NonShared/wikitest/WikiTestDS_v1_BS" typeId="BusinessService" xmlns:imp="http://www.bea.com/wli/config/importexport">
    <imp:properties>
      <imp:property name="dataclass" value="com.bea.wli.sb.resources.config.impl.XmlEntryDocumentImpl"/>
      <imp:property name="isencrypted" value="false"/>
    </imp:properties>
  </imp:exportedItemInfo>
</xml-fragment>

因此,在本例中,我希望替换具有typeId of ProxyService但没有其他任何一个的块中的命名空间。

EN

回答 1

Unix & Linux用户

发布于 2015-05-14 15:37:50

您可以使用sed只替换与特定模式匹配的行。

代码语言:javascript
复制
sed -e '/typeId="ProxyService"/s/xmlns:imp="http:\/\/www.bea.com\/wli\/config\/importexport"/xmlns:imp="http:\/\/www.bea.com\/wli\/config\/importexport2"/' new.xml

这只会在与“typeId=”ProxyService匹配的行中替换您的命名空间,我刚刚在您的名称空间中添加了一个2,但是您可以用您选择的任何字符串替换它。

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/203411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档