0

我正在制作一个带有 asp.net 加载 xml 文件的项目

在其中一个 xml 文件中,我有一个问题,我想显示一张图片并在不同的问题中闪烁。

<![CDATA[<a><img src="Study/1.png"/><a>]]>

那是我在 xml 中使用的代码,我的问题是它可以很好地显示 flash 内容和图像,但它没有关闭 cdata 属性,即

]]> 直接在图像或对象之后。

有任何想法吗?

这是我的xml

<?xml version="1.0" encoding="UTF-8"?>
<quiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xsi:noNamespaceSchemaLocation="quiz.xsd">
<mchoice>
    <question>For aircraft flying over the high seas, which rules shall be in force?  <![CDATA[<a><img src="Study/1.png"/></a>]]></question>
    <answer>The rules established by the state(s) adjacent to the high seas over flown </answer>
    <answer>The rules established by the state of the operator of the aircraft </answer>
    <answer correct="yes">The rules established by the state of registry of the aircraft </answer>
    <answer>The rules established under the Convention of international civil aviation </answer>
</mchoice>
     </quiz>

这是我的架构

   <?xml version="1.0" encoding="UTF-8"?>
   <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"    elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="quiz">
    <xs:complexType>
        <xs:choice>
            <xs:element name="mchoice" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="question" type="xs:string"/>
                        <xs:element name="answer" minOccurs="2" maxOccurs="unbounded">
                            <xs:complexType>
                                <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                        <xs:attribute name="correct" use="optional">
                                            <xs:simpleType>
                                                <xs:restriction base="xs:string">
                                                    <xs:enumeration value="yes"/>
                                                    <xs:enumeration value="no"/>
                                                </xs:restriction>
                                            </xs:simpleType>
                                               </xs:attribute>
                                         </xs:extension>
                                </xs:simpleContent>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:choice>
    </xs:complexType>
</xs:element>
 </xs:schema>

这是我的 xml 的 asp.net 代码

   Public Shared Function GetQuizDataFromXML(ByVal XMLFileName As String) As ArrayList
    Dim strXmlFilePath As String = XMLFileName
    Dim xDoc As XmlDocument = New XmlDocument()
    xDoc.Load(strXmlFilePath)
    Dim Arl As New ArrayList
    If Not IsNothing(xDoc) AndAlso xDoc.SelectNodes("/quiz/mchoice").Count > 0 Then
        Dim TotalQuestions As Integer = 0
        TotalQuestions = xDoc.SelectNodes("/quiz/mchoice").Count
        For i As Integer = 1 To TotalQuestions
            Dim strXPath As String = ""
            strXPath = "/quiz/mchoice[" & i.ToString() & "]"
            Dim oQ As New Questions
            oQ.QuestionID = i + 1
            oQ.Question = xDoc.SelectSingleNode(strXPath & "/question").InnerXml
            Dim xNodeList As XmlNodeList
            xNodeList = xDoc.SelectNodes(strXPath & "/answer")
            For j As Integer = 0 To xNodeList.Count - 1
                Dim oA As New Answers
                oA.QuestionID = oQ.QuestionID
                oA.Answer = xNodeList.Item(j).InnerText
                oA.AnswerID = j + 1
                Dim xNodeAttr As Object
                'Extract correct answer
                xNodeAttr = xNodeList.Item(j).Attributes.ItemOf("correct")
                oA.IsAnswer = False
                If Not xNodeAttr Is Nothing Then
                    If xNodeAttr.Value = "yes" Then
                        oA.IsAnswer = True
                    End If
                End If
                oQ.Answers.Add(oA)
            Next
            Arl.Add(oQ)
        Next
    End If
    Return Arl
    End Function
4

2 回答 2

1

也许尝试将整个问题放在下面的CDATA部分中

<question>
    <![CDATA[For aircraft flying over the high seas, which rules shall be in force? <a><img src="Study/1.png"/></a>]]>
</question>

如果这不能解决您的问题,请解决问题。从可行的方法开始并增加复杂性,直到出现问题。例如,<question>按此顺序修改标签(第一个应该可以)。

  1. <question>This is a test question</question>
  2. <question><![CDATA[This is a test question inside a CDATA tag]]></question>
  3. <question><![CDATA[This is a test question inside a CDATA tag with a <a>link</a>]]></question>
  4. <question><![CDATA[This is a test question inside a CDATA tag with a <a>link</a> and an image <img src="Study/1.png" />]]></question>
  5. <question><![CDATA[This is a test question inside a CDATA tag with a linked image <a><img src="Study/1.png" /></a>]]></question>
于 2013-01-14T09:46:42.660 回答
0

可能是因为<a>标签没有关闭吗?应该是</a>

更新

好吧,根据W3C 规范CDATA,该部分的标记似乎没有任何问题。

但是,由于您使用的是 ASP.net,根据这篇 MSDN 文章,您可以尝试用 替换]]>] ]>看看是否可行。

于 2013-01-13T16:18:44.080 回答