XML Samples with VB.NET? 
Author Message
 XML Samples with VB.NET?

I just read an article on devx.com
( http://www.*-*-*.com/
rticle) on the .NET xml parser (XmlTextReader) and was
hoping to play with it in VB (my "native tongue"). The
article uses C# for the example.

Its really my first foray into .NET beyond the "hello
world" tutorial, so I'm not sure if I'm doing something
wrong, but when I try and put the sample code from the
article into VB (and convert it to VB.NET Syntax), the
XmlTextReader object is not recognized. From what I
understand, you declare namespaces in the declarations
section to access the desired libaries (or whatever is the
correct term now).

I could find only one sample using the XML objects with
VB.NET, and when I copy and paste the code (see below),
the XmlTextReader object is "undefined" (build error). Can
anyone see what's wrong? I guess it a basic setup thing
with VB.NET I'm not getting.

Here's the VB.NET/XML code:

Option Explicit On
Option Strict On

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample

    Public Shared Sub Main()
        Dim reader As XmlTextReader = Nothing

        Try
            'Load the reader with the XML file.
            reader = New XmlTextReader("attrs.xml")

            'Read the ISBN attribute.
            reader.MoveToContent()
            Dim isbn As String = reader.GetAttribute
("ISBN")
            Console.WriteLine(("The ISBN value: " & isbn))

        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub 'Main
End Class 'Sample

Thanks.



Tue, 17 Feb 2004 01:01:31 GMT  
 XML Samples with VB.NET?


Quote:
> From what I
> understand, you declare namespaces in the declarations
> section to access the desired libaries (or whatever is the
> correct term now).

Kind of...

Using the "imports" statement gives you an easier way to access the name
of the object.  For example, you could do this:

System.Console.Writeline("line 1")
System.Console.Writeline("line 2")
System.Console.Writeline("line 3")
System.Console.Writeline("line 4")

or you could do this:

Imports System

Console.Writeline("line 1")
Console.Writeline("line 2")
Console.Writeline("line 3")
Console.Writeline("line 4")

So, imports is really just for coding.  Your problem relates to the fact
that you probably haven't added a reference to System.Xml.dll -- the
assembly that contains the System.Xml namespace.  Go to your project
references and add a reference to System.xml.dll.  If you're using the
command line compiler, add:

/r System.Xml.dll

To your command line.

--
Patrick Steele



Tue, 17 Feb 2004 01:34:35 GMT  
 XML Samples with VB.NET?

Yep, that's it. I knew it was just something basic I had
forgotten about from those introductory articles on
VB.NET. Thanks!

Quote:
>-----Original Message-----

(from Aaron

>> From what I
>> understand, you declare namespaces in the declarations
>> section to access the desired libaries (or whatever is
the
>> correct term now).

>Kind of...

>Using the "imports" statement gives you an easier way to
access the name
>of the object.  For example, you could do this:

>System.Console.Writeline("line 1")
>System.Console.Writeline("line 2")
>System.Console.Writeline("line 3")
>System.Console.Writeline("line 4")

>or you could do this:

>Imports System

>Console.Writeline("line 1")
>Console.Writeline("line 2")
>Console.Writeline("line 3")
>Console.Writeline("line 4")

>So, imports is really just for coding.  Your problem

relates to the fact
Quote:
>that you probably haven't added a reference to

System.Xml.dll -- the

- Show quoted text -

Quote:
>assembly that contains the System.Xml namespace.  Go to
your project
>references and add a reference to System.xml.dll.  If
you're using the
>command line compiler, add:

>/r System.Xml.dll

>To your command line.

>--
>Patrick Steele
>.



Tue, 17 Feb 2004 01:49:28 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Read XML using VB6 DOM 4.0 with Namespaces - See Sample XML

2. Date problems with XML in ASP.NET / VB.NET- newbie question

3. VB sample code using MS XML Parser?

4. VB.DOC 0.25 has been released - XML comments for VB.NET

5. Loadinf XML File using VB.net

6. VB .Net and XML

7. XML Tag look up VB.net?

8. editing xml documents using vb.net

9. XML and Datagrid in vb.net??

10. Application.config XML vb.net

11. Problem posting xml from vb.net client to asp classic page

12. vb.net newbie needs help with basic XML parsing

 

 
Powered by phpBB® Forum Software