ASP.NET Code
  Home arrow ASP.NET Code arrow Page 4 - 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

    Free Web 2.0 Code Generator! Generate data entry 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 (System.IO.Stream) method
    (Page 4 of 4 )

    The class FileStream inherits from System.IO.Stream as shown in the next picture. This is utilized to read the file from the drive as shown in the code that follows.

    Imports System.xml
    Partial Class LoadStream
       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
         Dim fs As New IO.FileStream( _
         "C:Inetpubwwwrootwebstudents.xml", _
         IO.FileMode.Open, IO.FileAccess.Read)
         xmldoc.Load(fs)
         Response.Write(xmldoc.HasChildNodes)
         Response.Write("<br/>")
         Response.Write("What is the Last Child? " & "<b>" & _
         xmldoc.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 file reference is passed as an argument, you may also pass a URL reference as in the Load (string) method discussed earlier.

    Load (System.XML.XMLReader) method

    The XMLReader is the API for parsing, and XMLTextReader, which inherits from the XMLReader, can be used for reading text or bytes.

    Imports System.xml
    Partial Class LoadXMLReader
       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
         Dim xmlrdr As New XmlTextReader( _
         "http://localhost/webstudents.xml")
         xmldoc.Load(xmlrdr)
         Response.Write(xmldoc.HasChildNodes)
         Response.Write("<br/>")
         Response.Write("What is the Last Child? " & "<b>" & _
         xmldoc.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 reference is passed as an argument, you may also pass a File reference as in the Load (string) method discussed earlier.

    Summary

    This tutorial has shown with examples the several ways in which an XML document can be loaded. Once loaded it can be parsed, or utilized in several ways. All of the examples take the same webstudents.xml file used in several other tutorials. The examples are provided with ample reference to the various classes and the namespaces and should provide an appropriate starting point for those venturing into XML using VS 2005.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 4 hosted by Hostway