在asp.net中显示分层xml - vb

时间:2011-01-25 12:53:26

标签: asp.net xml vb.net

我已经尝试将一些代码从c#转换为vb,但它不起作用,我不知道为什么。它应该呈现分层xml。

这是代码......

Private Sub Page_Load(sender As Object, e As EventArgs)
    Dim doc As New XmlDocument()
    doc.Load(Server.MapPath("~/myxml/getbooking.xml"))

    _rep1.DataSource = doc.FirstChild
    _rep1.DataBind()
End Sub

<asp:Repeater id="_rep1" runat="server" EnableViewState="false">
 <itemTemplate>
   Publisher: <%# CType(Container.DataItem, XmlNode).Attributes("name").Value  %><br/>
   <asp:Repeater runat="server" EnableViewState="false" DataSource='<%# Container.DataItem %>' >
     <itemTemplate>
       Author: <%# CType(Container.DataItem, XmlNode).Attributes("name").Value %><br/>
       <asp:Repeater runat="server" EnableViewState="false"
                  DataSource='<%# Container.DataItem %>' >
          <itemTemplate>
             <i>
          <%# CType(Container.DataItem, XmlNode).Attributes("name").Value  %>
          </i><br />
          </itemTemplate>
        </asp:Repeater>
     </itemTemplate>
   </asp:Repeater>
   <hr />
 </itemTemplate>
</asp:Repeater>

使用xml ...

<publishers>
 <publisher name="New Moon Books" city="Boston"
            state="MA" country="USA">
   <author name="Albert Ringer   ">
     <title name="Is Anger the Enemy?" />
     <title name="Life Without Fear" />
   </author>
   <author name="John White   ">
     <title name="Prolonged Data Deprivation " />
   </author>
   <author name="Charlene Locksley   ">
     <title name="Emotional Security: A New Algorithm" />
   </author>
   <author name="Marjorie Green   ">
     <title name="You Can Combat Computer Stress!" />
   </author>
 </publisher>
 <publisher name="Binnet and Hardley" city="Washington" 
            state="DC" country="USA">
   <author name="Sylvia Panteley   ">
     <title name="Onions, Leeks, and Garlic" />
   </author>
   <author name="Burt Gringlesby   ">
     <title name="Sushi, Anyone?" />
   </author>
   <author name="Innes del Castillo   ">
     <title name="Silicon Valley Gastronomic Treats" />
   </author>
   <author name="Michel DeFrance   ">
     <title name="The Gourmet Microwave" />
   </author>
   <author name="Livia Karsen   ">
     <title name="Computer Phobic AND Non-Phobic" />
   </author>
 </publisher>
 <!-- ... -->
</publishers>

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

为什么不在xml周围输出<xmp>标记?

<xmp>    
   <asp:literal id="myxml" runat="server" />
</xmp>

并在代码隐藏

myxml.Text = doc.InnerXml;