All pastes #352192 Raw Edit

Mine

public text v1 · immutable
·published 2007-02-12 17:24 UTC
rendered paste body
XmlDoc(src, set = "") {
	If set {
		FileDelete, %src%
		FileAppend, %set%, %src%
		Return, ErrorLevel
	}
	If FileExist(src)
		FileRead, src, %src%
	lt := "<", gt := ">", lf := "`n", il := StrLen(ic := "  "), len := 0
	Loop, Parse, src, %lt%
		If A_Index = 1
			Continue
		Else
			RegExMatch(SubStr(src, len += StrLen(txt)), "(?<=<).", next)
			doc .= InStr(tag := SubStr(txt := lt . A_LoopField
			, 1, InStr(txt, gt)), "/>") or RegExMatch(tag, "(\?|!|/)", del) = 2
			or !RegExMatch(txt, ">.*[^\s]") ? SubStr(i, 1
			+ il * (next = "/")) . tag . lf : i . txt . lf
			, i := del = "/" ? SubStr(i, 1 + il) : i . (del ? "" : ic)
	Return, RegExReplace(doc
		, "((?:" . ic . ")*)(<(\w+)\b[^<]*)\R\1(</\3>)", "$1$2$4")
}