web stats
Specifying xsi:nil="true" on XML element - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-17-2015, 06:08 PM
obsessio obsessio is offline
OBX.3 Kenobi
 
Join Date: Mar 2015
Location: Turkey
Posts: 164
obsessio is on a distinguished road
Angry Specifying xsi:nil="true" on XML element

I have XML to XML channel and I need to sent null values as null
(Stripe NameSpace option is unselected)
So I have inbound template which is below;
Code:
<mesaj xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <mesajBilgisi>
        <mesajTipi xsi:nil="true"/>
        <olayTipi xsi:nil="true"/>
        <mesajTarihi xsi:nil="true"/>
        <gonderenUygulama xsi:nil="true"/>
        <alanUygulama xsi:nil="true"/>
        <tesisAdi xsi:nil="true"/>
        <kontrolID xsi:nil="true"/>
    </mesajBilgisi>
    <masterBilgi>
        <aktif xsi:nil="true"/>
        <ilacMalzeme xsi:nil="true"/>
    </masterBilgi>
</mesaj>

and when I sent a message to channel, in transformation step "xsi:nil="true" properties removed from the message.

Code:
<mesaj xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <mesajBilgisi>
        <mesajTipi/>
        <olayTipi/>
        <mesajTarihi>20150918044728</mesajTarihi>
        <gonderenUygulama>Mirth</gonderenUygulama>
        <alanUygulama>IYS</alanUygulama>
        <tesisAdi>Tesis1</tesisAdi>
        <kontrolID>CID20150918044728458</kontrolID>
    </mesajBilgisi>
    <masterBilgi>
        <aktif/>
        <ilacMalzeme/>
    </masterBilgi>
</mesaj>
I think I missed something..

Channel attached
Mirth 3.3
Java 8.60
Attached Files
File Type: xml channel_example.xml (19.8 KB, 2 views)
Reply With Quote
  #2  
Old 09-19-2015, 04:08 AM
obsessio obsessio is offline
OBX.3 Kenobi
 
Join Date: Mar 2015
Location: Turkey
Posts: 164
obsessio is on a distinguished road
Default

I stucked here and I need your suggestions please.
Reply With Quote
  #3  
Old 09-24-2015, 02:10 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

I think the issue is that you're overwriting those nodes, so any attributes are reset. You can add that namespaced attribute back though, like this:

Code:
var xsi = new Namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
tmp['mesajBilgisi']['mesajTipi'].@xsi::nil = 'true';
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #4  
Old 09-24-2015, 03:18 PM
obsessio obsessio is offline
OBX.3 Kenobi
 
Join Date: Mar 2015
Location: Turkey
Posts: 164
obsessio is on a distinguished road
Default

Thank you very much Nick for your reply.

I added code but now it adds to every element even if element has value. Like;

Code:
<mesaj xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="file:///C:/sema.xsd" xsi:nil="true">
    <mesajBilgisi>
        <mesajTipi xsi:nil="true"/>
        <olayTipi xsi:nil="true"/>
        <mesajTarihi xsi:nil="true">20150925011504</mesajTarihi>
        <gonderenUygulama xsi:nil="true">Mirth</gonderenUygulama>
        <alanUygulama xsi:nil="true">IYS</alanUygulama>
        <tesisAdi xsi:nil="true">Tesis1</tesisAdi>
        <kontrolID xsi:nil="true">CID20150925011504801</kontrolID>
    </mesajBilgisi>
    <masterBilgi>
        <aktif xsi:nil="true"/>
        <ilacMalzeme xsi:nil="true"/>
    </masterBilgi>
</mesaj>
So I added if statement to check the element value is null or not and the result is perfect

Code:
var xsi = new Namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');

var a = tmp['mesajBilgisi']['mesajTarihi']
if (a === null) {
	a = tmp['mesajBilgisi']['mesajTarihi'].@xsi::nil = 'true';
}
For now my question is; I should create if statement for every element, like;

Code:
var xsi = new Namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');

var a = tmp['mesajBilgisi']['olayTipi']
if (a === null) {
	a = tmp['mesajBilgisi']['olayTipi'].@xsi::nil = 'true';
}

var b = tmp['mesajBilgisi']['kontrolID']
if (b === null) {
	tmp['mesajBilgisi']['kontrolID'].@xsi::nil = 'true';
}

var c = tmp['mesajBilgisi']['gonderenUygulama']
if (c === null) {
	tmp['mesajBilgisi']['gonderenUygulama'].@xsi::nil = 'true';
}

var d = tmp['mesajBilgisi']['mesajTarihi']
if (d === null) {
	tmp['mesajBilgisi']['mesajTarihi'].@xsi::nil = 'true';
}

.............................
...............
My JavaScript knowledge is limited. Is there any shortcode to check every element

Last edited by obsessio; 09-24-2015 at 03:20 PM.
Reply With Quote
  #5  
Old 10-01-2015, 10:07 AM
obsessio obsessio is offline
OBX.3 Kenobi
 
Join Date: Mar 2015
Location: Turkey
Posts: 164
obsessio is on a distinguished road
Default

Any idea for this if condition, how can I check all elements?

Code:
var xsi = new Namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');

var a = tmp['mesajBilgisi']['olayTipi']
if (a === null) {
	a = tmp['mesajBilgisi']['olayTipi'].@xsi::nil = 'true';
}

var b = tmp['mesajBilgisi']['kontrolID']
if (b === null) {
	b = tmp['mesajBilgisi']['kontrolID'].@xsi::nil = 'true';
}

var c = tmp['mesajBilgisi']['gonderenUygulama']
if (c === null) {
	c = tmp['mesajBilgisi']['gonderenUygulama'].@xsi::nil = 'true';
}

var d = tmp['mesajBilgisi']['mesajTarihi']
if (d === null) {
	d = tmp['mesajBilgisi']['mesajTarihi'].@xsi::nil = 'true';
}

.............................
...............

Last edited by obsessio; 10-15-2015 at 12:09 PM.
Reply With Quote
Reply

Tags
namespace, namespace xmlns, nil, xml, xsi

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:54 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation