允许嵌入 html 的 XML 模式 [英] XML Schema that allows embedding html
问题描述
在我的 xml 架构中,我有一个名为 itemsetting 的标签:
In my xml schema I have a tag named itemsetting:
<xs:element name="itemsetting">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="key" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="questionscript"/>
<xs:enumeration value="timeframe"/>
<xs:enumeration value="textlabel"/>
<xs:enumeration value="textboxtype"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
我想做的是能够将 html 嵌入到 questionscript 类型中.例如:
What I would like to do is to be able to embed html into a questionscript type. For example:
<itemsetting key="questionscript">this<html:b>is bold </html:b> </itemsetting>
我试图摆弄复杂/简单的时间,每次我最终都会得到一个无法解析的架构文件.指向正确方向的指针会很有帮助.
I've tried to fiddle with the complex/simple times and each time I end up with a schema file that is unable to be parsed. A pointer in the right direction would be very helpful.
推荐答案
扩展迈克尔的回答,如下所示:
Expanding on Michael's answer, something like this:
<xs:element name="itemsetting">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any namespace="http://www.w3.org/1999/xhtml" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="key" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="questionscript"/>
<xs:enumeration value="timeframe"/>
<xs:enumeration value="textlabel"/>
<xs:enumeration value="textboxtype"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
应该可行 - 假设 http://www.w3.org/1999/xhtml
是与 XML 中的 html
前缀相对应的 HTML 命名空间.
should work - assuming http://www.w3.org/1999/xhtml
is the HTML namespace corresponding to the html
prefix in your XML.
如果你有多个命名空间,或者你不想打扰命名空间检查,请使用
If you have multiple namespaces, or you don't want to bother with namespace checking use
. . .
<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded"/>
. . .
请注意,这假定嵌入的 HTML 是格式良好的 XML,例如,如果它不包含会使整个 XML 文件不可读的封闭标签,那么就无法使用架构.
Note that this assumes that the embedded HTML is well-formed XML, if - for example - it contains not closed tags that will make the whole XML file unreadable, and there is no way to use a schema then.
这篇关于允许嵌入 html 的 XML 模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!