2012-04-13 9 views
-1

このコードは、既存のxmlファイルから読み込んで内容をラベルに書き込むことになっていますが、動作しません。どこが間違っているのか分かりません。ヘルプをいただければ幸いです。xmlリーダーがxmlファイルを読み込んでラベルに表示していない

Dim reader As New XmlTextReader(Server.MapPath("~/ex01/docP.xml")) 
      'declare variable to record when a <name> element is found' 
      Dim bName As Boolean = False 
      'iterate through all of the nodes in the XML document' 
      While reader.Read() 
       'look at the node type of each node' 
       Select Case reader.NodeType 
        'if node is a <name> element, remember it' 
        Case XmlNodeType.Element 
         If reader.Name = "name" Then 
          bName = True 
         End If 
         'if node is text & previous node was <name>, add it to Label' 
        Case XmlNodeType.Text 
         If bName Then 
          lblDisplayXml.Text &= reader.ReadString & "<br/>" 
          'reset variable for next node' 
          bName = False 
         End If 
       End Select 
      End While 
     End Sub 
    End Class 

xmlファイル:

<?xml version="1.0" standalone="yes"?> 
<book_club> 
    <book> 
    <isbn>0-13-129014-2</isbn> 
    <title>JAVA How to Program (6th Ed)</title> 
    <author>PJ &amp; HM Deitel</author> 
    <price>£39.99</price> 
    </book> 
    <book> 
    <isbn>0-67-232238-2</isbn> 
    <title>Teach Yourself UML</title> 
    <author>J Schmuller</author> 
    <price>£9.99</price> 
    </book> 
    <book> 
    <isbn>0-27-365575-2</isbn> 
    <title>Practical Business Systems Development using SSADM</title> 
    <author>P Weaver, N Lambrou &amp; M Walkley</author> 
    <price>£34.99</price> 
    </book> 
    <book> 
    <isbn>0-67-232422-9</isbn> 
    <title>XML Primer Plus</title> 
    <author>N Chase</author> 
    <price>£32.99</price> 
    </book> 
    <book> 
    <isbn>0-78-972476-6</isbn> 
    <title>XML and Java from Scratch</title> 
    <author>N Chase</author> 
    <price>£19.99</price> 
    </book> 
    <book> 
    <isbn>1234567890</isbn> 
    <title>ASP.NET for Dummies</title> 
    <author>RUA Dummy</author> 
    <price>free!!</price> 
    </book> 
</book_club> 
+0

xmlファイルを表示できますか?また、lblDisplayXml.Textは繰り返し後に空になっていますか? –

+0

ねえ、xmlファイルを投稿しました。ラベルはブラウザで表示すると消えます。 – user1275084

+0

XMLにnameという要素が含まれていないようです。 '' reader.Name = "name" Then'の中で '' name "'を '' author "'や '' title "'に置き換えると、あなたのコードは出力を生成しますか? – JamieSee

答えて

0

あなたのXMLには< name>要素は、このようにラベルは任意の値を割り当てることはありません、ありません。

+0

あなたのXMLをチェックしてください –

関連する問題