首页 文章

如何从xml中删除命名空间

提问于
浏览
2

我有以下格式的XML

<Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/soap/envelope/">
  <TransactionAcknowledgement xmlns="">
    <TransactionId>HELLO </TransactionId>
    <UserId>MC</UserId>
    <SendingPartyType>SE</SendingPartyType>
  </TransactionAcknowledgement>
</Body>

我想为它使用XQuery或XPath表达式 .

现在我只想删除

xmlns:soap-env =“http://schemas.xmlsoap.org/soap/envelope/”

来自xml的命名空间 .

有没有办法实现它 .

谢谢

1 回答

  • 0

    尝试使用functx:change-element-ns-deep

    let $xml := <Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/soap/envelope/">
      <TransactionAcknowledgement xmlns="">
        <TransactionId>HELLO </TransactionId>
        <UserId>MC</UserId>
        <SendingPartyType>SE</SendingPartyType>
      </TransactionAcknowledgement>
    </Body>
    
    return functx:change-element-ns-deep($xml, "http://schemas.xmlsoap.org/soap/envelope/", "")
    

    但正如Dimitre Novatchev所说,这个函数不会改变源xml的命名空间,它会创建一个新的XML .

相关问题