最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Delete XML Atrributes - Stack Overflow

programmeradmin7浏览0评论

I am trying to write up some code in Mirth Connect that takes an XML tag and removes all attributes from inside of it.

Example:

<code nullFlavor="UNK" xsi:type="CD">

Desired result:

<code/>

I could do something like this:

delete msg['code']['@nullFlavor']
delete msg['code']['@xsi:type']

But I ideally want to handle ALL possible values that could come in, not just nullFlavor and xsi:type. Is there a way to do this?

I am trying to write up some code in Mirth Connect that takes an XML tag and removes all attributes from inside of it.

Example:

<code nullFlavor="UNK" xsi:type="CD">

Desired result:

<code/>

I could do something like this:

delete msg['code']['@nullFlavor']
delete msg['code']['@xsi:type']

But I ideally want to handle ALL possible values that could come in, not just nullFlavor and xsi:type. Is there a way to do this?

Share Improve this question asked Mar 27 at 2:48 Johnny TJohnny T 193 bronze badges 1
  • 2 Can't you replace the tag with a new tag that has no attributes? – Tim Roberts Commented Mar 27 at 2:54
Add a comment  | 

1 Answer 1

Reset to default 0

It can be achieved by running the following script-

// Get the <code> element
var myElement = msg['code'];

// Check if the element exists
if (myElement) {
    // Loop through all attributes and remove them
    for each (var attr in myElement.@*) {
        delete myElement['@' + attr.name()];
    }
}

// Return the modified message
msg;
发布评论

评论列表(0)

  1. 暂无评论