E:\web\learnaspcom\htdocs\freebook\learn\ubtoc.xml LearnAsp.com - ASP ASP.net Free Lessons
Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll
<Asp.net blog>
<personal site>
xxx

Using XMLDocument/DOM objects to Read XML Data by Charles Carroll

Here is code to read an XML File with an XMLDocument/DOM objects

   filename=/experiments/booksfave/domreader.aspx

<Test Script Below>


<%@trace="true" debug="true" %>
<%@ Import Namespace="System.XML"%>
<%@ Import Namespace="System.Drawing"%>
<script language="VB" runat="server">
Sub Page_Load(S As Object, E As EventArgs)
    trace.tracemode=TraceMode.SortByTime
    
    DIM Xmldom1 as XMLDocument
    
    TRY
        Xmldom1=new XMLDocument()
        XmlDom1.Load(server.mappath("/experiments/data/favebooks.xml"))
        DIM strTemp as string
        
        DIM ndlst1 as XMLNodeList
        DIM nd1,nd2 as XMLnode
        DIM intChildNodeCounter as integer
        
        ndlst1=XMLdom1.GetElementsByTagName("book")
        
        FOR each nd1 in ndlst1
            trace.write (".name",nd1.name)
            'trace.write (".innertext",nd1.innertext)
            'trace.write (".haschildnodes",nd1.haschildnodes)
            'trace.write (".childnodes.count",nd1.childnodes.count)
            
            FOR intChildNodeCounter=0 TO nd1.childnodes.count-1
                nd2=nd1.ChildNodes(intChildNodeCounter)
                trace.write ("child node" & intChildNodeCounter & ".name",nd2.name)
                trace.write ("child node" & intChildNodeCounter & ".innertext",nd2.innertext)
            NEXT
        NEXT

    CATCH ex1 as exception
    
    FINALLY
        
    END TRY
End Sub

</script>
<html><head>
<title>XML Demo</title>
</head>
<body bgcolor="#FFFFFF">
<form runat="server">
<ASP:placeholder id="plcErr" runat="server" />
See The Trace For More Details
<AsP:Table id="tblXMlDetails" runat="server" />
<ASP:placeholder id="plcEndofPage" runat="server" />
</form>
</body></html>
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.