如何使用 e4x 生成的 XML 以 HTML 方式关闭元素?

发布于 2024-08-09 17:50:03 字数 592 浏览 10 评论 0原文

我正在使用 e4x 为我的用户生成一个 HTML 片段,他们可以复制并查看该片段。粘贴到他们的博客或网站中:

var xml: XML = <object>
                   <param name="..."></param>
                   <param name="..."></param>
                   <embed args="..."></embed>
               </object>;
var html: String = xml.toXMLString();

但是,没有子元素的标签使用较短的 变体而不是 < /code> 位于输出 HTML 字符串中,这会在将代码粘贴到 Blogger 编辑器等中时导致一些问题。

有没有办法强制以 HTML 方式关闭标签,或者有​​一个好的解决方法吗?在 之间添加注释似乎不起作用。

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. the 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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2024-08-16 17:50:03

在 XML 对象中表示 HTML 在这里似乎不是一个好主意。 HTML 片段无论如何都只会被视为文本:您不会对其执行任何 XML 操作。
只需将其直接构建为字符串即可。这样,它的格式就完全按照您的需要,您可以包含注释,...

如果您确实愿意,您可以通过确保该 xml 元素的内容不为空,使其输出带有 XML 对象的单独结束标记。您不希望文本之间有任何实际文本,但只需一个空格就足够了。在 Flex 中(我不知道其他动作脚本实现),您可能必须将 XML.ignoreWhitespace 设置为 false 才能正常工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文