将 HTML 与基于 XML 的语言(如 SVG)结合使用的最佳实践是什么?

发布于 2024-07-05 16:09:41 字数 378 浏览 6 评论 0原文

通过浏览本网站和其他网站,我了解到目前以 XHTML 形式提供网站被认为是有害的

目前大多数浏览者并不支持提供 XHTML 并将其作为 application/xhtml+xml 提供,将 xhtml 作为 text/html 提供最多只是一个安慰剂我自己,最坏的情况是在你最不需要的时候破坏网站的秘诀。

所以我们最终回到了 html 4.01。 如果我将页面作为 html 4.01 提供服务,是否可以在页面上使用 SVG 或任何其他基于 XML 的语言?

如果是这样,怎么办?

From browsing on this site and elsewhere, I've learned that serving websites as XHTML at present is considered harmful.

Delivering XHTML and serving it as application/xhtml+xml isn't supported by the majority of people browsing at present, delivering xhtml as text/html is at best a placebo for myself, and at worst a recipe for breaking sites usually when you least need it happening.

So we end up back at html 4.01. If I instead serve my pages as html 4.01, is it possible to use SVG or any other XML-based language on the page?

If so, how?

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

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

发布评论

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

评论(2

淡淡の花香 2024-07-12 16:09:41

在 HTML 中,您无法直接插入 SVG。

您可以使用 / 嵌入 SVG 文件,在尖端浏览器(Opera、Safari)中也可以使用 和 CSS <代码>背景图像。

您可以将 SVG 放入 data: URI 中以避免使用外部文件。

可以借助 Unicode 和基本 HTML/CSS 编写简单的数学表达式(Opera 9.5 支持通过 CSS 实现大块 MathML)。 对于更复杂的事情,您需要使用图像,就像维基百科那样。

HTML 会误解名称空间前缀,因此您将无法(正确)将其他 XML 标记与 HTML DOM 一起使用。 HTML5 具有用于添加特定于应用程序的标记的 data-* 属性。 对于元数据,请考虑微格式。

但是,如果您只想为非浏览器(机器人)嵌入 XML,那么您可以使用 HTML 兼容的 XHTML 子集和 HTTP 内容协商来将具有正确类型的正确 XML 发送给理解它的客户端(如果您在 XML 和 HTML 模式下彻底测试页面,那么它不会有害)。

In HTML you won't be able to insert SVG directly.

You can embed SVG files with <object>/<embed> and in cutting-edge browsers (Opera, Safari) also <img> and CSS background-image.

You can put SVG in data: URI to avoid using external files.

Simple mathematical expressions can be written with help of Unicode and basic HTML/CSS (Opera 9.5 supports large chunk of MathML via CSS). For anything more complex you'll need to use images, like Wikipedia does.

HTML misinterprets namespace prefixes, so you won't be able to (properly) use other XML markup with HTML DOM. HTML5 has data-* attributes for application-specific markup additions. For metadata consider Microformats.

However if you want to embed XML only for non-browsers (robots), then you could use HTML-compatible XHTML subset and HTTP content negotiation to send proper XML with proper type to clients that understand it (if you thoroughly test page in both XML and HTML modes, then it won't be harmful).

把人绕傻吧 2024-07-12 16:09:41

您可以(请阅读我自己没有尝试过)使用嵌入对象并相应地键入它。

You may (read I haven't tried this myself) to use an embedded object and type it accordingly.

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