我希望使用sed替换xml文件中的命名空间(我已经放弃了尝试从ant (需要它的地方)进行命名空间的尝试)。主要问题是,有一个重复的元素列表-并不是所有的元素都需要替换。
Xml文件:
<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但没有其他任何一个的块中的命名空间。
发布于 2015-05-14 15:37:50
您可以使用sed只替换与特定模式匹配的行。
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,但是您可以用您选择的任何字符串替换它。
https://unix.stackexchange.com/questions/203411
复制相似问题