There are some built in rules in exporting that automatically create Void elements / self closing tags for some tags:
ExportString[XMLElement["input", {}, {}], "HTMLFragment"]
"<input class=\"form-control\"/>"
but the default is
ExportString[XMLElement["test", {"attr"->"val"}, {}], "HTMLFragment"]
"<test attr=\"val\"></test>"
Q: Is there any "proper" way to tell ExportString
to return "<test attr=\"val\">"
or "<test attr=\"val\" />"
?
Of course, one can do:
StringReplace[
ExportString[XMLElement["test", {"attr" -> "val"}, {}], "HTMLFragment"],
"></" ~~ LetterCharacter .. ~~ ">" ~~ EndOfString -> ">"
]
"<test attr=\"val\">"
but that's ugly.
Except of the general approach, nicer work arounds are also appreciated.
<rect spec />
syntax, but<rect spec></rect>
seem to work too, so maybe I should not care? $\endgroup$