web stats
Remove !DOCTYPE in HTML response without ext library - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-19-2017, 02:07 AM
vibinChander vibinChander is offline
OBX.2 Kenobi
 
Join Date: Jul 2015
Location: Chennai
Posts: 74
vibinChander is on a distinguished road
Send a message via Skype™ to vibinChander
Default Remove !DOCTYPE in HTML response without ext library

Im receiving
HTML Code:
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
as a part of HTML response. I tried accessing this response inside response tab. We are concerned about deployment so we are not going for external Java library like Jsoup html parser. In this case how can we achieve this?. I basically want to remove DOCTYPE and fetch the response content using XML parser provided by Mirth.

When I do it normally, it says DOCTYPE is not accepted.

Using JSOUP its working fine as provided below.

Code:
importPackage(org.jsoup);
var doc = Jsoup.parse(msg);
var tds = doc.getElementsByTag("h2");
var text = tds.text();
var responseStatusValue = text.substring(0,3);
if(responseStatusValue=='401')
{
	logger.debug("Data : "+ text.substring(0,3));	
	router.routeMessage('TEST - client', '');	
}
I tried making the response type as RAW and built the below code:

Code:
var updateMsg= new XML (msg).replace('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">','')
var newMsg= new XML (updateMsg);
logger.debug('XML : '+newMsg);
var responseData = newMsg['head']['title'].toString(); 
logger.debug(newMsg['head']['title'])
var responseDataStatus = responseData.substring(0,3);
but the code var
HTML Code:
 responseData = newMsg['head']['title'].toString();
is not returning anything.

Is there a way to overcome this issue?
__________________

Mirth Interface Engineer
AWS DevOps
Reply With Quote
  #2  
Old 09-19-2017, 03:21 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

Are you sure the replace call is working as intended? Try echoing that out to verify that the DOCTYPE is indeed gone first.
__________________
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 09-25-2017, 03:59 AM
vibinChander vibinChander is offline
OBX.2 Kenobi
 
Join Date: Jul 2015
Location: Chennai
Posts: 74
vibinChander is on a distinguished road
Send a message via Skype™ to vibinChander
Wink replace did not work

The replace function did not work. I tried replacing <!DOCTYPE it wasnt helping more over I wanted to have my response transformer as XML not as RAW, so if it is XML it is throwing unspecified XML character <!DOCTYPE.

I used $('responseStatusLine') to identify weather the response is either 200 or 401 or 500. Now it is working.

But curious to know how to parse html data without using libraries in the response transformer. only in response transformer.

Because using pre-processor or attachment javascript properties we can remove that if we are going to use source transformer.
__________________

Mirth Interface Engineer
AWS DevOps
Reply With Quote
Reply

Tags
html, mirth 3.4.2, 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 02:54 AM.


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