英文:
Extend "Is valid Xhtml" validator for Rich Text Field in Sitecore
问题
无法翻译代码部分,以下是已翻译的内容:
"The 'Is valid Xhtml' validator for Rich Text Field in Sitecore does not accept Html valid attributes like: role, aria, data-... etc."
Trying to find a solution over the internet led to the majority of answers which were to disable the validator, which makes an area for the content author's error. Also, there were suggestions to make the change directly in the Sitecore file, which also has one drawback - makes upgrades a bit more difficult in the future.
This link has shed some light on the final solution:
Override XHTML validation for Rich Text Fields in Sitecore
英文:
The "Is valid Xhtml" validator for Rich Text Field in Sitecore does not accept Html valid attributes like: role, aria, data-... etc.
Trying to find a solution over the internet led to the majority of answers which were to disable the validator, which makes an area for the content author's error. Also, there were suggestions to make the change directly in the Sitecore file, which also has one drawback - makes upgrades a bit more difficult in the future.
This link has shed some light on the final solution:
Override XHTML validation for Rich Text Fields in Sitecore
答案1
得分: 0
在一些调查之后,发现“Is valid Xhtml”验证器在验证过程中使用了XSD模式。幸运的是,有一种扩展它的方法。
以下是步骤:
- 创建一个名为XSD模式文件的自定义文件,例如"[Customer Name] Sitecore xhtml5.xsd",其中包含以下内容(例如,对于我的情况):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
targetNamespace="http://www.w3.org/1999/xhtml"
elementFormDefault="qualified">
<xs:include schemaLocation="Sitecore xhtml5.xsd"/>
<xs:redefine schemaLocation="Sitecore xhtml5.xsd">
<xs:complexType name="styledFlowContentElement">
<xs:complexContent>
<xs:extension base="styledFlowContentElement">
<xs:attribute name="aria-label" type="xs:string"/>
<xs:attribute name="row" type="xs:string"/>
<xs:attribute name="data-video-id" type="xs:string"/>
<xs:attribute name="aria-describedby" type="xs:string"/>
<xs:attribute name="role" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
</xs:schema>
它通过"xs:include"包含了原始的XSD文件,并通过"xs:redefine"扩展了所需的元素,增加了我的情况下的属性。
将其放在MSVS项目的以下文件夹层次中:"sitecore\shell\Schemas\[Customer Name] Sitecore xhtml5.xsd"。确保文件的"Build Action"为"Content"(右键单击->属性)。
- 创建补丁文件:
<sitecore>
<settings>
<setting name="XHtmlSchemaFile" value="/sitecore/shell/schemas/[Customer Name] Sitecore xhtml5.xsd"/>
</settings>
</sitecore>
这样就不会再出现关于未定义属性的错误。
英文:
After some investigation, it was found, that under the hood "Is valid Xhtml" validator is utilizing XSD schema for the validation process. Happily, there is a way to extend it.
Here are the steps:
- Create a customer specifically named XSD Schema file e.g. "[Customer Name] Sitecore xhtml5.xsd", which will contain the next content (e.g. for my case):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
targetNamespace="http://www.w3.org/1999/xhtml"
elementFormDefault="qualified">
<xs:include schemaLocation="Sitecore xhtml5.xsd"/>
<xs:redefine schemaLocation="Sitecore xhtml5.xsd">
<xs:complexType name="styledFlowContentElement">
<xs:complexContent>
<xs:extension base="styledFlowContentElement">
<xs:attribute name="aria-label" type="xs:string"/>
<xs:attribute name="row" type="xs:string"/>
<xs:attribute name="data-video-id" type="xs:string"/>
<xs:attribute name="aria-describedby" type="xs:string"/>
<xs:attribute name="role" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
</xs:schema>
It includes the original xsd file (via "xs:include") and extending necessary element (via "xs:redefine") with additional for my case attributes.
Place it in MSVS project in the next hierarchy of folders "sitecore\shell\Schemas\[Customer Name] Sitecore xhtml5.xsd". Make sure file's "Build Action" is "Content" (right click -> properties):
- Create patch file:
<sitecore>
<settings>
<setting name="XHtmlSchemaFile" value="/sitecore/shell/schemas/[Customer Name] Sitecore xhtml5.xsd"/>
</settings>
</sitecore>
And there are no more errors regarding undefined attributes.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论