You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

含SVG命名空间的XHTML文档XML Schema验证问题求助

含SVG命名空间的XHTML文档XML Schema验证问题

我有一份包含SVG标签的XHTML文档,必须引入SVG命名空间才能在网页上正常显示SVG内容。为该文档编写XML Schema进行验证时,执行XQuery出现多个针对带命名空间的SVG元素的错误。

查阅资料(本站、O'Reilly《XML Schema》、Wrox《Beginning XML》)后,了解到可使用xs:any、xs:annotation和xs:documentation元素解决此类问题,但因从未接触过该场景,不确定最佳方案。

初始XHTML代码

<html xmlns="http://www.TedTheSpeedlearner.com" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TedTheSpeedlearner.com SVG_Bezier_Curve_Webpage_XML_Schema.xsd">
<head>
     <title>SVG_Bezier_Curve</title>
     <link rel="stylesheet" type="text/css" href="http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Bezier_Curve.css"/>
     <script language="javascript" src="http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Bezier_Curve_2.js">
     </script>
</head>
<body onload="Setup()">
     <input type="button" id="Bezier_Curve_Button" value="Click Me!" onclick="Setup2()"/>
     <svg:svg id="My_SVG" height="500" width="500">
     <svg:path id="Bezier_Curve_1"/>
     <svg:path id="Bezier_Curve_2"/>
     </svg:svg>
</body>
</html>

初始XML Schema代码

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:target="http://www.TedTheSpeedlearner.com" targetNamespace="http://www.TedTheSpeedlearner.com" elementFormDefault="qualified">
<complexType name="HeadType">
    <sequence>
        <element name="head" type="target:TitleType"/>
        <element name="body" type="target:BodyType"/>
    </sequence>
</complexType>
<complexType name="TitleType">
    <sequence>
        <element name="title" type="string"/>
        <element name="link" type="target:LinkType"/>
        <element name="script" type="target:ScriptType"/>
    </sequence>
</complexType>
<complexType name="LinkType">
    <attribute name="rel" type="string"/>
    <attribute name="type" type="string"/>
    <attribute name="href" type="string"/>
</complexType>
<complexType name="ScriptType">
    <attribute name="language" type="string"/>
    <attribute name="src" type="string"/>
</complexType>
<complexType name="BodyType">
    <sequence>
        <element name="input" type="target:InputType"/>
        <element name="svg" type="target:SvgType"/>
    </sequence>
    <attribute name="onload" type="string"/>
</complexType>
<complexType name="SvgType">
        <sequence>
        <element name="path" type="PathType"/>
        <element name="path" type="Path2Type"/>
        </sequence>
        <attribute name="id" type="string"/>
        <attribute name="height" type="string"/>
        <attribute name="width" type="string"/>
</complexType>
<complexType name="InputType">
    <attribute name="type" type="string"/>
    <attribute name="id" type="string"/>
    <attribute name="value" type="string"/>
    <attribute name="onclick" type="string"/>
</complexType>
<complexType name="PathType">
    <attribute name="id" type="string"/>
</complexType>
<complexType name="Path2Type">
    <attribute name="id" type="string"/>
</complexType>
<element name="html" type="target:HeadType"/>
</schema>

错误及调试尝试

执行XQuery后,出现多个针对带命名空间的SVG元素的验证错误。后续尝试了以下调试步骤:

  • 修复PathType定义后部分错误消失,在Schema根元素添加SVG命名空间声明,并将body中的svg元素改为<svg:element name="svg" type="target:SvgType"/>,出现新错误,提示SVG元素不属于目标命名空间。
  • 尝试为HTML标签添加body命名空间,修改XHTML和Schema后,出现命名空间错误,无法识别带body前缀的元素。
  • 将script标签改为自闭合形式后,仍存在HTML标签的验证错误。
  • 简化Schema结构、调整命名空间声明、添加XML声明并修改schemaLocation后,HTML标签的验证问题解决,但SVG命名空间仍无法被识别。尝试编写单独的SVG Schema并导入,因未正确使用ref属性失败。

已知XML Schema验证实例文档时仅默认识别单个命名空间,需通过导入其他Schema解决多命名空间验证问题,但此前尝试未成功。现寻求正确的验证方案,解决含SVG命名空间的XHTML文档的XML Schema验证问题。


内容的提问来源于stack exchange,提问作者Speedlearner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 03:14:54