-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathxmlPrettify.ahk
51 lines (47 loc) · 1.31 KB
/
xmlPrettify.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
XmlPrettify(input, params) {
return sXML_Pretty(input)
}
XmlUglify(input, params) {
return sXML_Pretty(input, "")
}
sXML_Pretty( XML, IndentationUnit="`t" ) { ; Adds linefeeds (LF, asc 10) and indentation between XML tags.
; NOTE: If the XML does not begin with a "<?xml...?>" tag, the output will begin with a newline.
StringLen, il, IndentationUnit
Loop, Parse, XML, <
If ( A_Index = 1 )
VarSetCapacity( XML, Round( StrLen( XML ) * ( A_IsUnicode ? 2.3 : 1.15 ) ), 0 )
Else
Loop, Parse, A_LoopField, >, % "`t`n`r " Chr( 160 )
If ( A_Index = 1 )
{
closetag := SubStr( A_LoopField, 1, 1 )
emptytag := SubStr( A_LoopField, 0 )
If ( closetag = "?" ) && ( emptytag = "?" )
XML := "<" A_LoopField
Else
{
If ( closetag = "/" )
{
StringTrimRight, indent, indent, il
If ( priortag ) {
If ( il )
XML .= "`n"
XML .= indent
}
}
Else
{
If ( il )
XML .= "`n"
XML .= indent
If ( emptytag != "/" ) && ( closetag != "!" )
indent .= IndentationUnit
}
XML .= "<" A_LoopField
}
priortag := closetag = "/" || closetag = "!" || emptytag = "/"
}
Else
XML .= ">" A_LoopField
Return Trim(XML, " `t`n`r")
} ; END - sXML_Pretty( XML, IndentationUnit="`t" )