vb.net 2005 code doesn't work in vb.net 2003, HELP!!!!!!!!!

GetCod

vb.net 2005 code doesn't work in vb.net 2003, HELP!!!!!!!!!

by GetCod » Thu, 07 Mar 2013 23:32:23

VbCode Why doesn't it work.

Why doesn't my code work. I am working with vb.net 2003 and I was following an example in .net 2005.The code is very short. I am only having a problem with one line. If someone test this out on there 2003 version You must have an xml file in th same folder that you have you executable named cars.xml. This code was placed in a button click event. The xml Code and vb code is below. The word Oldsmobole Should appear in the textbox. HEELLLLPPP!!! I keep having a problemn with line 4, of which I highlighted in red.

Im geting An unhandled exception of type 'System.Xml.XmlException' occurred in system.xml.dll

Additional information: System error.

< xml version="1.0" encoding ="utf-8" >

<carlot>

<car><Make>Oldsmobile</Make>

</car>

</carlot>

1 Dim sr As New System.IO.StreamReader("Cars.xml")

2 Dim xr AS New System.Xml.XmlTextReader(sr)

3 Dim CarLotDoc AS New System.Xml.XmlDocument

4 CarLotDoc.Load(xr)

5 Label1.Text = CarLotDoc.InnerText




Martin Honne

vb.net 2005 code doesn't work in vb.net 2003, HELP!!!!!!!!!

by Martin Honne » Sun, 10 Mar 2013 00:33:24

I have already suggested to you to check the exception you get e.g.

Dim CarLotDoc As New XmlDocument

Try

CarLotDoc.Load("Cars.xml")

'Continue here to access the document

Catch ex as XmlException

Console.WriteLine("Failed to load XML, error: {0}, line: {1}, position: {2}", ex.Message, ex.LineNumber, ex.LinePosition)

End Try

You will then see the error message and line number/position the XML parser reports, where the error will probably be about the space character after the " " and before the "xml" in the XML declaration, that is not allowed.

So you need to correct your XML to e.g.

< xml version="1.0" encoding="utf-8" >

<carlot>

<car><Make>Oldsmobile</Make>

</car>

</carlot>



Martin Honne

vb.net 2005 code doesn't work in vb.net 2003, HELP!!!!!!!!!

by Martin Honne » Mon, 11 Mar 2013 02:35:26

MSDN has this section about exception handling in the .NET framework. I guess if you ask in a VB.NET forum for introductions/tutorials about exception handling with VB.NET then you will get more links and if you then ask specific questions if you do not understand something you will find help there. This forum is not the right place to deal with the basics of VB.NET or other .NET languages that are not XML related.


GetCod

vb.net 2005 code doesn't work in vb.net 2003, HELP!!!!!!!!!

by GetCod » Tue, 12 Mar 2013 01:34:25

You are absotuley right I had a space in my xml code. Could you explain that error catch technique to me all over again, I am kinda new to vb.