简体   繁体   English

如何在 W3C 验证器上验证 XML 命名空间?

[英]How XML namespaces are validated on W3C validator?

I have two files:我有两个文件:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   width="210mm"
   height="297mm"
   viewBox="0 0 210 297"
   version="1.1"
   id="svg5"   
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   inkscape:version="1.1.1 (c3084ef, 2021-09-22)"
   xmlns="http://www.w3.org/2000/svg">
</svg>

This one validates fine on W3C validator.这个在 W3C 验证器上验证得很好。 But once I edit the namespace, ie URI in xmlns:inkscape it starts to fail:但是一旦我编辑命名空间,即xmlns:inkscape中的 URI,它就会开始失败:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   width="210mm"
   height="297mm"
   viewBox="0 0 210 297"
   version="1.1"
   id="svg5"   
   xmlns:inkscape="http://www.inkscape.org/namespaces/ABC"
   inkscape:version="1.1.1 (c3084ef, 2021-09-22)"
   xmlns="http://www.w3.org/2000/svg">
</svg>

It gives me this error:它给了我这个错误:

Line 10, Column 38: Attribute version from namespace http://www.inkscape.org/namespaces/ABC not allowed on SVG element svg at this point.第 10 行,第 38 列:来自命名空间http://www.inkscape.org/namespaces/ABC的属性版本在 SVG 元素 svg 上不允许。

I use https://validator.w3.org/ for validating it.我使用https://validator.w3.org/来验证它。 I have to upload these as .svg files.我必须将这些上传为.svg文件。 I can not paste it into direct input, as it doesn't detect the format and there is no such selection in the manual choice ( SVG 1.1 + URL + HTML + MathML 3.0 is detected in file upload).我无法将其粘贴到直接输入中,因为它没有检测到格式,并且在手动选择中没有这样的选择( SVG 1.1 + URL + HTML + MathML 3.0在 A A 文件上传中检测到)。

What kind of black magic is going on here?这里发生了什么样的黑魔法? I thought those URIs are pretty free-form, but it looks like W3C validator pulls some sort of schema from somewhere even if nothing is specified.我认为这些 URI 的格式非常自由,但看起来 W3C 验证器从某个地方提取了某种模式,即使没有指定任何内容。

I also noticed that I can rename the namespace to something else and it all works as long as I keep the same URI.我还注意到我可以将命名空间重命名为其他名称,只要我保持相同的 URI,它就可以正常工作。

How does validation of namespaces work?命名空间的验证如何工作? I'm just trying to add my custom namespace to my SVG files...我只是想将我的自定义命名空间添加到我的 SVG 文件中......

The "magic" can be found by looking at the sources :通过查看来源可以找到“魔法”:

  1. All files that do not have a DOCTYPE declaration, and all files that have a .svg extension are checked by delegation to the Nu Html Checker :所有没有DOCTYPE声明的文件,以及所有具有.svg扩展名的文件都由Nu Html 检查器进行检查

     # we send doctypeless SVG, or any doctypeless XML document with multiple # namespaces found, to a different engine. WARNING this is experimental.
  2. As you found, this validator identifies the file as SVG 1.1 + URL + HTML + MathML 3.0 .如您所见,此验证器将文件标识SVG 1.1 + URL + HTML + MathML 3.0 These files are checked via a Relax NG scheme called svg-xhtml5-rdf-mathml.rnc .这些文件通过名为svg-xhtml5-rdf-mathml.rnc的 Relax NG 方案进行检查。 And that file explicitely checks against the inkscape namespace .并且该文件明确地检查了 inkscape 命名空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM