Question Kryštof Matějka · Nov 2, 2016

html beautifier

Hello,

I'm sending http request through %Net.HttpRequest and I have html page in response. Is there any built-in tool for beautify html for printing in terminal?
Thanks.

Comments

Dmitry Maslennikov · Nov 2, 2016

In Caché you can't do so, without any external tools. And anyway, most of beautifiers works only in some IDEs, you can just copy output and beautify in VisualStudio Code as example.

0
Kyle Baxter · Nov 2, 2016

You could dump it out to a file on the filesystem and just view it in your browser/favorite editor.

0
Jorge de la Garza · Nov 2, 2016

I know of no such built in tool, however here's a routine I wrote to pretty print an XML string:

PrettyPrintXML(pXML)	for tI = 1:1:10 write ! }	set tTabCount = 0	// if starting with an XML prolog, do not increment tab on next line	if ($E(pXML,1,5)="<?xml") 		set tI = $FIND(pXML,">")		set $EXTRACT(pXML,tI-1) = ">"_$C(13,10) 	}	else set tI = 1 	for {		set tI = $FIND(pXML,"<",tI) quit:tI=0		//cdata		if ($EXTRACT(pXML,tI,tI+7)="![CDATA[") {			//set tTabCount = tTabCount + 1			do Tabs			set $EXTRACT(pXML,tI-1) = tTabs_"<"			set tI = $FIND(pXML,">",tI) quit:tI=0			set $EXTRACT(pXML,tI-1) = ">"_$C(13,10)			//set tTabCount = tTabCount - 1		}		//open tag		elseif ($EXTRACT(pXML,tI) '= "/") {			do Tabs			set $EXTRACT(pXML,tI-1) = tTabs_"<"			set tI = $FIND(pXML,">",tI) quit:tI=0			// only increment tab count if this is not an empty tag (<tag/>)			if ($E(pXML,tI-2)'="/") set tTabCount = tTabCount + 1 }			//if followed by another open tag, insert a newline before it			if ($EXTRACT(pXML,tI) = "<") set $EXTRACT(pXML,tI) = $C(13,10)_"<" }		}		//close tag		else {			set tTabCount = tTabCount - 1			//if following another close tag, put tabs before this one ($C(62) = ">")			if ($EXTRACT(pXML,tI-4,tI-2) = $C(62,13,10)) {				do Tabs				set $EXTRACT(pXML,tI-1) = tTabs_"<"			}			set tI = $FIND(pXML,">",tI) quit:tI=0			set $EXTRACT(pXML,tI-1) = ">"_$C(13,10)		}	}	write pXML	quitTabs	set tTabs = ""	for i=1:1:tTabCount set tTabs = tTabs_$C(9) }	quit
0