I'm using e4x to generate a HTML-snippet for my users which they can copy & paste into their blogs or web sites:
var xml: XML = <object>
<param name="..."></param>
<param name="..."></param>
<embed args="..."></embed>
</object>;
var html: String = xml.toXMLString();
however, the tags without child elements are closed using the shorter <embed/>
-variant rather than <embed></embed>
in the output HTML-string , which causes some problems when the code is pasted into e.g. th开发者_如何学Goe Blogger editor.
Is there a way to force the HTML-way of closing tags or is there a good workaround? Putting comments between <embed>
and </embed>
doesn't seem to work..
Representing HTML in XML objects doesn't seem like a good idea here. The HTML-snippet will only be treated as text anyways: you won't do any XML operations on it.
Just build it directly as a String. That way it is formatted exactly as you want, you can include comments,...
If you really want to, you can make it output a separate closing tag with the XML object by making sure the content of that xml element is not empty. You don't want any real text between the text, but just a space would be enough. In Flex (I don't know about other actionscript implementations) you'll probably have to set XML.ignoreWhitespace to false for that to work.
精彩评论