web stats
writing xml tags from DB to xml file - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2018, 03:05 PM
dmro dmro is offline
What's HL7?
 
Join Date: Feb 2018
Posts: 2
dmro is on a distinguished road
Default writing xml tags from DB to xml file

I have some xml tags stored in a DB that I am trying to write to file. When I use a DB reader and get these and write them to file, the ">" and "<" of the xml tags are getting replaced by "&gt;" and "&lt;" in the file. This is problematic with the program that is reading it as it doesn't do any parsing to the xml file and just skips over what should be tags..
this is what the tags are..
<document>
<file-name>F810B80C-C292-416C-A62F-EF4A96972696.pdf</file-name>
</document>
and they are getting put into the file as:

&lt;attachement_document&gt;&lt;document&gt;&lt;fi le-name&gt;F810B80C-C292-416C-A62F-EF4A96972696.pdf&lt;/file-name&gt;&lt;/document&gt;&lt;/attachement_document&gt;

Thanks!
Reply With Quote
  #2  
Old 02-08-2018, 10:49 AM
collinsmj collinsmj is offline
OBX.1 Kenobi
 
Join Date: Jun 2014
Location: Southern USA
Posts: 27
collinsmj is on a distinguished road
Default

A bit more info would assist us in helping you.

1. What version of Mirth are you using?

2. What is the data type of the field these values come from within your database?

3. How is reading the html encoded string breaking the final program? Are you just using Mirth as a passthru?



I would approach this issue first by making sure the datatype from the query/sproc is returning XML and not a regular var char.

could you post your sql from the DB reader and the DB schema for the fields in question.

you could also attempt a preprocessor script that does a string replace on &gt; with > and &lt; with <. This way your RAW source text will be what you need in the destination.


Or the first source transformer could be a string replace instead of using the preprocessor script.
Reply With Quote
  #3  
Old 02-08-2018, 01:09 PM
dmro dmro is offline
What's HL7?
 
Join Date: Feb 2018
Posts: 2
dmro is on a distinguished road
Default

1. 3.5.1
2. It was a varchar, I changed it to an xml data type but i am still getting the same problem..
3. Yes it is just a pass through. I am trying to get an additional couple pieces of info from a database and put those in the xml file. To do this i have created 2 channels. The first channel reads the original xml file and puts the values in a field. The second channel gets the info that i want to add and then writes the file to a new location. Its this second channel that i am having issues with the original xml tags going back into the xml file properly.

Ive tried using the preprocessor and the replace functions, but it still doesn't show properly..

If there is a better way to accomplish the described, please let me know i am fairly new to mirth.
Attached Files
File Type: xml Write XML File.xml (37.3 KB, 23 views)
Reply With Quote
  #4  
Old 02-08-2018, 09:34 PM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 841
siddharth is on a distinguished road
Default

I think you might want to wrap that XML column around a CDATA tag.
__________________
HL7v2.7 Certified Control Specialist!
Reply With Quote
  #5  
Old 02-08-2018, 09:52 PM
Thoughts_Shared Thoughts_Shared is offline
OBX.2 Kenobi
 
Join Date: Dec 2016
Posts: 64
Thoughts_Shared is on a distinguished road
Default

Quote:
Originally Posted by dmro View Post
I have some xml tags stored in a DB that I am trying to write to file. When I use a DB reader and get these and write them to file, the ">" and "<" of the xml tags are getting replaced by "&gt;" and "&lt;" in the file. This is problematic with the program that is reading it as it doesn't do any parsing to the xml file and just skips over what should be tags..
this is what the tags are..
<document>
<file-name>F810B80C-C292-416C-A62F-EF4A96972696.pdf</file-name>
</document>
and they are getting put into the file as:

&lt;attachement_document&gt;&lt;document&gt;&lt;fi le-name&gt;F810B80C-C292-416C-A62F-EF4A96972696.pdf&lt;/file-name&gt;&lt;/document&gt;&lt;/attachement_document&gt;

Thanks!
&lt; (<), &amp; (&), &gt; (>), &quot; ("), and &apos; (') are encoding
or special characters of XML and cannot be printed directly in the Document Writer. You need to replace them with the defined characters and they will print correctly.

You can replace them in the Preprocessor like:

message = message.replace(/&/g, '&amp;');
message = message.replace(/</g, "&lt;");

You can replace the characters you need.
Reply With Quote
  #6  
Old 05-31-2019, 01:49 PM
johansanchez johansanchez is offline
Mirth Newb
 
Join Date: May 2019
Posts: 6
johansanchez is on a distinguished road
Smile writing xml tags from DB to xml file

Hi please help me

how can I use this script

message = message.replace(/&/g, '&amp;');
message = message.replace(/</g, "&lt;");


I have this
Mapping: msg['examenid'].toString()

its content in a database is XML

<examenid>903871</examenid><examenid>903816</examenid>

but read the following

<examenid>903818&lt;903816&lt;903815&lt;903868&lt; 903842&lt;</examenid>

Thank you friend for your help

Mirth connect version 3.7.0
Reply With Quote
  #7  
Old 06-01-2019, 07:26 AM
johansanchez johansanchez is offline
Mirth Newb
 
Join Date: May 2019
Posts: 6
johansanchez is on a distinguished road
Default

Quote:
Originally Posted by Thoughts_Shared View Post
&lt; (<), &amp; (&), &gt; (>), &quot; ("), and &apos; (') are encoding
or special characters of XML and cannot be printed directly in the Document Writer. You need to replace them with the defined characters and they will print correctly.

You can replace them in the Preprocessor like:

message = message.replace(/&/g, '&amp;');
message = message.replace(/</g, "&lt;");

You can replace the characters you need.
Hi Friend
can you tell me how to use that expression in mapping?

Thank you for reply
Reply With Quote
Reply

Tags
db reader, file writer, xml error, xml tags

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 06:37 PM.


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