xquery:如何删除xml节点中未使用的命名空间?

xquery:如何删除xml节点中未使用的命名空间?,xquery,basex,Xquery,Basex,我有一个与以下内容相同的xml文档: <otx xmlns="http://iso.org/OTX/1.0.0" xmlns:i18n="http://iso.org/OTX/1.0.0/i18n" xmlns:diag="http://iso.org/OTX/1.0.0/DiagCom" xmlns:measure="http://iso.org/OTX/1.0.0/Measure" xmlns:string="http://iso.org/OTX/1.0.0/StringUtil

我有一个与以下内容相同的xml文档:

   <otx xmlns="http://iso.org/OTX/1.0.0" xmlns:i18n="http://iso.org/OTX/1.0.0/i18n" xmlns:diag="http://iso.org/OTX/1.0.0/DiagCom" xmlns:measure="http://iso.org/OTX/1.0.0/Measure" xmlns:string="http://iso.org/OTX/1.0.0/StringUtil" xmlns:dmd="http://iso.org/OTX/1.0.0/Auxiliaries/DiagMetaData" xmlns:fileXml="http://vwag.de/OTX/1.0.0/XmlFile" xmlns:log="http://iso.org/OTX/1.0.0/Logging" xmlns:file="http://vwag.de/OTX/1.0.0/File" xmlns:dataPlus="http://iso.org/OTX/1.0.0/DiagDataBrowsingPlus" xmlns:event="http://iso.org/OTX/1.0.0/Event" xmlns:quant="http://iso.org/OTX/1.0.0/Quantities" xmlns:hmi="http://iso.org/OTX/1.0.0/HMI" xmlns:math="http://iso.org/OTX/1.0.0/Math" xmlns:flash="http://iso.org/OTX/1.0.0/Flash" xmlns:data="http://iso.org/OTX/1.0.0/DiagDataBrowsing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="http://iso.org/OTX/1.0.0/DateTime" xmlns:eventPlus="http://iso.org/OTX/1.0.0/EventPlus" xmlns:corePlus="http://iso.org/OTX/1.0.0/CorePlus" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:job="http://iso.org/OTX/1.0.0/Job" id="id_4e5722f2f81a4309860c146fd3c743e5" name="NewDocument1" package="NewOtxProject1Package1" version="1.0.0.0" timestamp="2014-04-11T09:42:50.2091628+07:00">
  <declarations>
    <constant id="id_fdc639e20fbb42a4b6b039f4262a0001" name="GlobalConstant">
      <realisation>
        <dataType xsi:type="Boolean">
          <init value="false"/>
        </dataType>
      </realisation>
    </constant>
  </declarations>
  <metaData>
    <data key="MadeWith">Created by emotive Open Test Framework - www.emotive.de</data>
    <data key="OtfVersion">4.1.0.8044</data>
  </metaData>
  <procedures>
    <procedure id="id_1a80900324c64ee883d9c12e08c8c460" name="main" visibility="PUBLIC">
      <realisation>
        <flow/>
      </realisation>
    </procedure>
  </procedures>
</otx>

由emotive开放测试框架创建-www.emotive.de
4.1.0.8044
我想通过xquery删除xml中不受约束的名称空间,但我不知道有什么解决方案。当前使用的命名空间是“和”。

请帮帮我

不幸的是,XQuery Update没有提供用于删除现有名称空间的表达式,但您可以递归地重新生成文档:

declare function local:strip-ns($n as node()) as node() {
  if($n instance of element()) then (
    element { node-name($n) } {
      $n/@*,
      $n/node()/local:strip-ns(.)
    }
  ) else if($n instance of document-node()) then (
    document { local:strip-ns($n/node()) }
  ) else (
    $n
  )
};

let $xml :=
  <A xmlns="used1" xmlns:unused="unused">
    <b:B xmlns:b="used2"/>
  </A>
return local:strip-ns($xml)
declare function local:strip ns($n as node())as node(){
如果($n元素()的实例),则(
元素{节点名($n)}{
$n/@*,
$n/node()/local:strip ns(.)
}
)否则,如果($n document-node()的实例),则(
文档{local:strip ns($n/node())}
)否则(
$n
)
};
让$xml:=
返回本地:strip ns($xml)

有趣的问题,我现在没能做到。然而,你为什么要这样做?最后,这些未使用的名称空间不应该真正困扰您。这是我的项目的一个要求。但是为什么呢?如果你这样做,我看不出有什么好处,但是如果这是一项要求,那么一定有人认为这对项目是有益的。这背后应该有原因的,真的。我不知道是什么原因,但它来自客户端,如果可能的话,我必须实现它