web stats
Building XML with attributes only - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-27-2014, 08:43 AM
seaston seaston is offline
OBX.3 Kenobi
 
Join Date: Feb 2010
Location: London, UK
Posts: 168
seaston is on a distinguished road
Default Building XML with attributes only

Hi there.

Does anyone know why this produces nothing in the channelMap?

Code:
 
var ecvi = <ecvi/>;
ecvi.@studyCode = "30";
ecvi.@ptTitle = "Mr";
ecvi.@ptFirstNames = "TEST";
ecvi.@ptLastName = "PATIENT";
 
channelMap.put("ecvixml",ecvi);
It is ok as soon as I add an element, but I cannot seem to build ecvi with attributes only as required.

Simon
Reply With Quote
  #2  
Old 08-27-2014, 09:21 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,117
narupley is on a distinguished road
Default

That node is simple, so the default toString only returns the underlying text element. If you want the XML node regardless, use toXMLString() instead.
__________________
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
  #3  
Old 08-27-2014, 09:31 AM
seaston seaston is offline
OBX.3 Kenobi
 
Join Date: Feb 2010
Location: London, UK
Posts: 168
seaston is on a distinguished road
Default

Thanks Nick. I have been trying to figure that out for ages!

I hope I am adding namespace in the correct way?

Code:
var ecvi = <ecvi/>;
//default xml namespace='http://tempuri.org/ecviSchema.xsd';
ecvi.setNamespace(new Namespace('', 'http://tempuri.org/ecviSchema.xsd'));
ecvi.@studyCode = "30";
ecvi.@ptTitle = "Mr";
ecvi.@ptFirstNames = "TEST";
ecvi.@ptLastName = "PATIENT";

channelMap.put("ecvixml",ecvi.toXMLString());
Reply With Quote
  #4  
Old 08-27-2014, 09:47 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,117
narupley is on a distinguished road
Default

Quote:
Originally Posted by seaston View Post
Thanks Nick. I have been trying to figure that out for ages!

I hope I am adding namespace in the correct way?

Code:
var ecvi = <ecvi/>;
//default xml namespace='http://tempuri.org/ecviSchema.xsd';
ecvi.setNamespace(new Namespace('', 'http://tempuri.org/ecviSchema.xsd'));
ecvi.@studyCode = "30";
ecvi.@ptTitle = "Mr";
ecvi.@ptFirstNames = "TEST";
ecvi.@ptLastName = "PATIENT";

channelMap.put("ecvixml",ecvi.toXMLString());
Yeah that's fine. If you need to set a specific bound prefix to the current node:

Code:
node.setNamespace(new Namespace('prefix', 'namespace'));
If you want to add the namespace definition (with a particular prefix) for use in descendant nodes:

Code:
node.addNamespace(new Namespace('prefix', 'namespace'));
__________________
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
Reply

Tags
attributes, xml

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 11:17 AM.


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