ASP.NET Code
  Home arrow ASP.NET Code arrow Page 3 - How to Load XML Documents in ASP.NET 2.0
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET CODE

How to Load XML Documents in ASP.NET 2.0
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 12
    2007-02-20

    Table of Contents:
  • How to Load XML Documents in ASP.NET 2.0
  • Loading an XMLDocument
  • Load (string) where string is an XML file
  • Load (System.IO.Stream) method

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    How to Load XML Documents in ASP.NET 2.0 - Load (string) where string is an XML file
    (Page 3 of 4 )

    The Load (string) method takes as an argument the reference to an XML file located in the file system as shown in the following code.

    Imports system.xml
    Partial Class LoadString
       Inherits System.Web.UI.Page

       Protected Sub Button1_Click(ByVal sender As Object, _
       ByVal e As System.EventArgs) Handles Button1.Click
       Dim xmldoc As New XmlDocument
       xmldoc.Load("C:Inetpubwwwrootwebstudents.xml")
       Response.Write("Loaded as an xml file located on the C drive<br/>")
       Response.Write("Does the document has child nodes? " _
       & "<b>" & xmldoc.HasChildNodes & "</b>")
       Response.Write("<br/>")
       Response.Write("What is the Last child? " & "<b>" _ 
       & xmldoc.DocumentElement.LastChild.InnerXml & "</b>")
       Response.Write("<br/>")
       Response.Write("What is Last child's Last child? " & _
       "<b>" & xmldoc.DocumentElement.LastChild.LastChild.InnerXml _
       & "</b>")
       End Sub
    End Class

    Again the DOM API is used to look at the Last child and the Last child's Last child as in the code. The browser display for this is shown in the next picture.

    Load (System.IO.TextReader) method

    The next picture shows the System.IO.TextReader class. The Read() method of this will be invoked to load the xml as in the code.

    Imports System.xml
    Partial Class LoadWithTextReader
       Inherits System.Web.UI.Page

       Protected Sub Button1_Click(ByVal sender As Object, _
       ByVal e As System.EventArgs) Handles Button1.Click

         Dim docxml As New XmlDocument

         Dim rdr As New XmlTextReader( _
         "http://localhost/webstudents.xml")
         rdr.Read()
         docxml.Load(rdr)
         Response.Write("What is the Last Child? " & "<b>" & _
         docxml.DocumentElement.LastChild.InnerXml & "</b>")
       End Sub
    End Class

    Again the DOM API is used to look at the Last child as in the code. The browser display for this is shown in the next picture. Although a URL is passed as an argument, you may also pass a file reference as in the Load (string) method discussed earlier.

    It may be noted that the StreamReader class can also be used to read the XML from the file as a text  from its Read() method since the StreamReader inherits from the System.IO.TextReader as shown in the next picture.

    More ASP.NET Code Articles
    More By Jayaram Krishnaswamy


       · XMLDocument class a full service class to address all needs of an XML document....
     

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway