我想在XML文件中使用html标记,因此在我的xsd文件中,我通过以下方式允许html格式化:
<xs:element name="description">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any namespace="http://www.w3.org/1999/xhtml"
processContents="lax"
minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>在我的XML文件中
<description>
<p xmlns="http://www.w3.org/1999/xhtml"> This course is an introduction to the information technologies required for secure, practical information systems for electronic commerce.
Topics will be chosen from areas such as document representation (XML, DTDs, XML Schema, XSLT, CSS),
</p> security (encryption, public key, symmetric key,
PKI, authentication); kinds of attack and vulnerabilities, electronic trading (spontaneous, deliberative, auctions), electronic document management
(metadata, search, digital libraries, management and processing), recent developments and maturation of the area,
such as web application frameworks, web services, the semantic web , mobile commerce </description>但是,当我将其更改为HTML文件时,它没有显示任何内容!(无p)
我无法将html标记放入xsl文件中,因为我想在description标记(XSD的一个元素)中划分内容。如果有什么新奇的方式,我会接受的。
起初,甚至连<p xmlns="http://www.w3.org/1999/XHTML">都不能工作,我把processContents=设为“lax”,它工作得很好,但仍然显示了一大堆段落(所以<p>不能真正工作)
我怎么才能让它工作呢?
发布于 2012-09-19 11:02:14
使用您给出的最小示例,XML将根据您提供的XSD片段进行验证(在将xs:schema添加为根元素之后)。
example.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="description">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any namespace="http://www.w3.org/1999/xhtml"
processContents="lax"
minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>test.xml:
<description>
<p xmlns="http://www.w3.org/1999/xhtml"> This course is an introduction to the information technologies required for secure, practical information systems for electronic commerce.
Topics will be chosen from areas such as document representation (XML, DTDs, XML Schema, XSLT, CSS),
</p> security (encryption, public key, symmetric key,
PKI, authentication); kinds of attack and vulnerabilities, electronic trading (spontaneous, deliberative, auctions), electronic document management
(metadata, search, digital libraries, management and processing), recent developments and maturation of the area,
such as web application frameworks, web services, the semantic web , mobile commerce </description>验证:
$ xmllint --noout --schema example.xsd test.xml
test.xml validates所以我不知道你有什么问题。
出现在脑海中的一个问题是您可能没有使用xhtml。包含在description元素(或任何超文本标记语言)中的超文本标记语言()必须是有效的xml (因此是xhtml,而不是类似sgml的草率的超文本标记语言语法),包括使任何xhtml命名的字符实体(例如, )可用于模式验证器。几乎你在网络上找到的任何html都绝对不是有效的xml。
如果希望使html可用于XML处理程序和验证,请使用XHTML 1.1及其XSD提供的XHTML 1.0 xsd或(更灵活地)混合和匹配模块。
如果这对您来说太麻烦了,并且您可以将HTML内容视为一大堆文本,那么只需将其作为文本内容包含进来,并修改您的xsd模式,使其期望xs:string或xs:normalizedString作为description元素的内容。
发布于 2012-09-19 09:54:09
将html内容包装在CDATA标记中:
<![CDATA[<p>stuff</p>]]>来自msdn:
当解析器遇到初始
<![CDATA[时,它会将后面的内容报告为字符,而不会尝试将它们解释为元素或实体标记。字符引用在CDATA节中不起作用。当遇到结束]]>时,解析器停止报告并返回到正常解析。
https://stackoverflow.com/questions/12487499
复制相似问题