简体   繁体   English

cdata注意到在asp.net xml中关闭

[英]cdata noting closing in asp.net xml

I am making a project with asp.net loading xml files 我正在使用asp.net加载XML文件的项目

in one of the xml files i have a question and i want to display a picture and flash in different questions. 在一个xml文件中,我有一个问题,我想显示图片并在不同的问题中闪烁。

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

that is the code i using in my xml, my problem is its displaying both flash content and images fine but it is not closing the cdata property ie 那是我在我的xml中使用的代码,我的问题是它可以很好地显示Flash内容和图像,但是没有关闭cdata属性,即

]]> directly after an image or object. ]]>直接在图像或对象之后。

any ideas? 有任何想法吗?

heres my xml 这是我的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>

here is my schema 这是我的图式

   <?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>

here is my asp.net code for the xml 这是我的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

Maybe try putting the entire question in the CDATA section as below 也许尝试将整个问题放在CDATA部分中,如下所示

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

If that doesn't solve your problem then work through the problem. 如果那不能解决您的问题,请解决问题。 Start with what works and add complexity until something breaks. 从可行的方法开始,并增加复杂性直到出现问题。 For example, modify the <question> tag in this order (the first one should work). 例如,按此顺序修改<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>

Could it be because the <a> tag isn't closed ? 可能是因为<a>标记未关闭? It should be </a> . 应该是</a>

Update 更新资料

Well, there doesn't seem to be anything wrong with the markup of the CDATA section, as per the W3C specification . 嗯,按照W3C规范CDATA部分的标记似乎没有什么错。

However, since you're using ASP.net, according to this MSDN article , you could try replacing ]]> with ] ]> , and see if that works. 但是,由于您使用的是ASP.net,因此,根据此MSDN文章 ,您可以尝试将]]>替换为] ]> ,看看是否可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM