xquery:如何删除 xml 节点中未使用的命名空间? [英] xquery: how to remove unused namespace in xml node?

查看:33
本文介绍了xquery:如何删除 xml 节点中未使用的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a xml document same as:

   <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>

我想通过 xquery 删除 xml 中未使用的命名空间,但我不知道解决它的任何解决方案.当前使用的命名空间是 "http://iso.org/OTX/1.0.0http://www.w3.org/2001/XMLSchema-instance".
请帮帮我!

I want to remove unsused namespaces in the xml by xquery but i don't know any solution to solving it. the current namespace used are "http://iso.org/OTX/1.0.0 and http://www.w3.org/2001/XMLSchema-instance".
please help me!.

推荐答案

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

Unfortunately, XQuery Update provides no expression to remove existing namespaces, but you can recursively rebuild your document:

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)

这篇关于xquery:如何删除 xml 节点中未使用的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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