0

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なし)

内容をdescriptionタグ(XSDの1つの要素)内で分割したかったため、htmlタグをxslファイルに入れることができませんでした。何か斬新な方法があれば、私はそれを受け入れます。

最初は、<p xmlns="http://www.w3.org/1999/XHTML">機能しませんでした。processContents= "lax"を入力すると、正常に機能しましたが、段落全体が1つ表示されました(実際に<p>は機能しません)。

どうすればそれを機能させることができますか?

4

2 に答える 2

7

HTMLコンテンツをCDATAタグでラップします。

<![CDATA[<p>stuff</p>]]>

msdnから:

XMLパーサーがイニシャル<![CDATA[に遭遇すると、要素またはエンティティのマークアップとして解釈しようとせずに、後続のコンテンツを文字として報告します。文字参照はCDATAセクション内では機能しません。結論に達する]]>と、パーサーはレポートを停止し、通常の解析に戻ります。

于 2012-09-19T01:54:09.437 に答える
3

指定した最小限の例を使用して、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

だから私はあなたの問題が何であるかわかりません。

頭に浮かぶ問題の1つは、xhtmlを使用していない可能性があることです。description要素(または任意のHTML)に含めるHTMLは、有効なxml(したがって、ずさんなsgmlのようなhtml構文ではなくxhtml )である必要があります。これには、xhtmlの名前付き文字エンティティ(たとえば)をスキーマバリデーターで使用できるようにすることも含まれます。&nbsp;Web上で見つけたほとんどすべてのhtmlは、絶対に有効なxmlではありません。

htmlをXMLプロセッサと検証で利用できるようにする場合は、XHTML 1.0 xsdを使用するか、(より柔軟に)XHTML1.1とそのXSDから利用できるモジュールを組み合わせて使用​​します

これが非常に問題であり、HTMLコンテンツをテキストのブロブとして扱うことに問題がない場合は、それをテキストコンテンツとして含め、xsdスキーマを変更して期待するxs:stringか要素xs:normalizedStringのコンテンツとして使用してください。description

于 2012-09-19T03:02:14.183 に答える