簡體   English   中英

從多名稱空間XML中刪除名稱空間的數據

[英]Remove data of a namespace from a Multi NameSpace XML

我有一個XML,如下所示。 該XML具有3個命名空間中的元素。 我想刪除1個命名空間的數據和元素/屬性,並保留帶有2個namepsaces及其元素的最終XML。

開發環境: 1. Spring 2. Java 8

<ns1:animals xmlns:ns1="http://.../animal" xmlns:ns2="http://.../tiger" xmlns:ns3="http://.../fish">
        <ns1:animalDescription>
            <ns1:animalType>fish</ns1:animalType>
            <ns1:animalLength>VALUE</ns1:animalLength>
            <ns1:partsOfBody>
               <ns1:eyes ns3:isCompund="true">
                  <ns1:countOfEyes>100</ns1:countOfEyes>
               </ns1:eyes>
               <ns3:gills>bigGills</ns3:gills>
         </ns1:animalDescription>
            <ns1:animalDescription>
            <ns1:animalType>TIGER</ns1:animalType>
            <ns1:animalLength>3 meter</ns1:animalLength>
            <ns1:partsOfBody>
               <ns1:eyes>
                  <ns1:countOfEyes>2</ns1:countOfEyes>
               </ns1:eyes>
               <ns2:tailLength>1 Meter</ns2:tailLength>
         </ns1:animalDescription>
    <ns1:animals>

我想刪除nameSpace xmlns:ns3 =“ http://.../fish”。 我想要如下的最終XML。 我已經嘗試過執行字符串操作,但對於復雜的xsd而言卻沒有用。 我想使用任何XML API來執行此操作。 請指導我。 該用什么來達到目的。 我正在尋找有效的解決方案。

<ns1:animals xmlns:ns1="http://.../animal" xmlns:ns2="http://.../tiger" xmlns:ns3="http://.../fish">
        <ns1:animalDescription>
            <ns1:animalType>fish</ns1:animalType>
            <ns1:animalLength>VALUE</ns1:animalLength>
            <ns1:partsOfBody>
               <ns1:eyes>
                  <ns1:countOfEyes>100</ns1:countOfEyes>
               </ns1:eyes>

         </ns1:animalDescription>
         <ns1:animalDescription>
            <ns1:animalType>TIGER</ns1:animalType>
            <ns1:animalLength>3 meter</ns1:animalLength>
            <ns1:partsOfBody>
               <ns1:eyes>
                  <ns1:countOfEyes>2</ns1:countOfEyes>
               </ns1:eyes>
               <ns2:tailLength>1 Meter</ns2:tailLength>
         </ns1:animalDescription>
    <ns1:animals>

FINAL XML沒有以下數據。 1. ns3:isCompund =“ true” 2. bigGills

在XSLT 3.0中:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
  <xsl:mode on-no-match="shallow-copy"/>
  <xsl:template match="ns3:* ! @ns3:*" xmlns:ns3="http://.../fish"/>
</xsl:transform>

如果只有XSLT 1.0或2.0,則將xsl:mode聲明替換為標准的淺拷貝身份模板規則。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM