SVG 中的 XPointer

发布于 2024-08-26 11:19:21 字数 1422 浏览 13 评论 0原文

我一直在尝试让 XPointer URI 在 SVG 文件中工作,但到目前为止还没有任何运气。在尝试了更复杂的方法并失败后,我将其简化为仅引用 ID。然而,这仍然失败。

该规范似乎对此实现非常清楚:

http://www.w3.org /TR/SVG/struct.html#URIReference

我在网上找到了一个示例,说明 svg 文档中的工作 XPointer 引用应该是什么。这是 原创。这是我复制的版本:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="500" height="200" version="1.1" 
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink">

    <defs>
        <rect id="simpleRect" width="100px" height="75px"/>
    </defs>
    <use xlink:href="#simpleRect" 
        x="50" y="50" style="fill:red"/>
    <use xlink:href="#xpointer(id('simpleRect'))" 
        x="250" y="50" style="fill:yellow"/>
</svg>

这应该显示两个矩形......一个红色,一个黄色。我尝试使用 Firefox 3.6 和 Inkscape 0.47 进行渲染。没有成功。仅显示红色矩形。

我缺少什么?

感谢您提供的任何帮助

I've been trying to get XPointer URIs working in an SVG file, but haven't had any luck so far. After trying something more complicated and failing, I simplified it down to just referencing an ID. However, this still fails.

The spec seems pretty clear about this implementation:

http://www.w3.org/TR/SVG/struct.html#URIReference

I found an example online of what should be a working XPointer reference within an svg document. Here is the Original. Here is the version I copied out:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="500" height="200" version="1.1" 
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink">

    <defs>
        <rect id="simpleRect" width="100px" height="75px"/>
    </defs>
    <use xlink:href="#simpleRect" 
        x="50" y="50" style="fill:red"/>
    <use xlink:href="#xpointer(id('simpleRect'))" 
        x="250" y="50" style="fill:yellow"/>
</svg>

This should display two rectangles... one red and one yellow. I tried rendering with Firefox 3.6 and Inkscape 0.47. No success. Only the Red rectangle shows.

What am I missing?

Thanks for any help you can offer

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

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

发布评论

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

评论(2

苏别ゝ 2024-09-02 11:19:21

目前(截至 2016 年 3 月 10 日,SVG 1.1 第二版)不支持在浏览器中渲染 XPointers。 W3Schools对此的描述如下

XPointer 浏览器支持

没有浏览器支持 XPointer。但 XPointer 也用于其他 XML 语言。

这有点令人沮丧,因为所有官方文档都没有费心区分 SVG 的浏览器支持(Internet 就绪)功能和 SVG 技术支持的、纯粹类似 XML 的功能。

There is currently (as of 10 March 2016, SVG 1.1 Second Edition) no support for rendering XPointers in browsers. W3Schools writes about this as follows:

XPointer Browser Support

There is no browser support for XPointer. But XPointer is used in other XML languages.

It's kind of frustrating, because all the official documentation does not bother to distinguish between browser-supported (Internet ready) features of SVG and the technically-supported, purely XML-like features of SVG.

谜泪 2024-09-02 11:19:21

来自规范的 链接部分

<URI-reference> = [ <absoluteURI> | <relativeURI> ] [ "#" <elementID> ]    -or-
<URI-reference> = [ <absoluteURI> | <relativeURI> ] [ "#xpointer(id(" <elementID> "))" ]

那么这样做的好处是什么使用 xpointer 语法?我见过的所有 svg 实现都支持上面显示的替代(较短)语法 (#myId)。 xpointer 语法似乎不太受支持。

From the linking section of the spec:

<URI-reference> = [ <absoluteURI> | <relativeURI> ] [ "#" <elementID> ]    -or-
<URI-reference> = [ <absoluteURI> | <relativeURI> ] [ "#xpointer(id(" <elementID> "))" ]

So what is the benefit of using xpointer syntax? All svg implementions I've seen have supported the alternative (shorter) syntax shown above (#myId). The xpointer syntax seems to be less well supported.

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