473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Reading XML file getting error

I'm new to XML files so I'm kinda lost here. I found some example code
on reading an XML file.

My objective is simple. Read the whole XML file into memory.

Here is part of my code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim query As String
Dim Node As XmlNode
Dim sReturnedValue As String

'Add any initialization after the InitializeComponent() call
configFileName = "i:\rpg\configs\config2.xml"
document = New XmlDocument
document.Load(configFileName)

query = "descendant::company[@id='dmo']"
Node = document.DocumentElement.SelectSingleNode(query)
'("descendant::book[@bk:ISBN='1-861001-57-6']", nsmgr)
If Not Node Is Nothing Then
sReturnedValue = Node.Attributes.GetNamedItem("value").Value

Else
MsgBox("Could not find node" & LookFor & " in config file")
End If

End Sub

Here is the error I am getting when I get to the RED line in my code:

An unhandled exception of type 'System.NullReferenceException' occurred
in XML Test.exe

Additional information: Object reference not set to an instance of an
object.

My XML File looks like this:

<?xml version="1.0"?>
<config>
<company id="dmo">
<DefaultBranch>"02"</DefaultBranch>
<TruckSystemType>"MS"</TruckSystemType>
<TruckSystemDataDrive>"D:"</TruckSystemDataDrive>
<CompaniesOnSystem>"3"</CompaniesOnSystem>
<SalesAndServicePrinter>"P1"</SalesAndServicePrinter>
<DeliveryTicketPrinter>"P2"</DeliveryTicketPrinter>
<CounterReceiptPrinter>"P3"</CounterReceiptPrinter>
<TypeTapeBackup>"PKZ"</TypeTapeBackup>
<StatementForm>"Y"</StatementForm>
<OnePartForm>"0000"</OnePartForm>
<TwoPartForm>"0001"</TwoPartForm>
<RemotePath>"i:\rpg"</RemotePath>
<LocalPath>"c:\rpg"</LocalPath>
<CompanyEmailAddress>"te**@ss.com"</CompanyEmailAddress>
<DefaultUserName>"Master"</DefaultUserName>
<DefaultWorkstationID>"AA"</DefaultWorkstationID>
<RpgStartUpFile>"c:\rpg\gas\aastart.p"</RpgStartUpFile>
</company>
</config>

Any ideas what I am doing wrong?

Thanks!
Eroc

Jun 14 '06 #1
3 1604

Eroc wrote:
I'm new to XML files so I'm kinda lost here. I found some example code
on reading an XML file.

My objective is simple. Read the whole XML file into memory.

Here is part of my code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim query As String
Dim Node As XmlNode
Dim sReturnedValue As String

'Add any initialization after the InitializeComponent() call
configFileName = "i:\rpg\configs\config2.xml"
document = New XmlDocument
document.Load(configFileName)

query = "descendant::company[@id='dmo']"
Node = document.DocumentElement.SelectSingleNode(query)
'("descendant::book[@bk:ISBN='1-861001-57-6']", nsmgr)
This appears to be part of the problem. Looks like you have the code
from the sample still referencing the book:ISBN, and your XML file does
not contain that node name.

I prefer parsing XML using the XMLSerializer class. Leaves all values
in nice convenient properties.


If Not Node Is Nothing Then
sReturnedValue = Node.Attributes.GetNamedItem("value").Value

Else
MsgBox("Could not find node" & LookFor & " in config file")
End If

End Sub

Here is the error I am getting when I get to the RED line in my code:

An unhandled exception of type 'System.NullReferenceException' occurred
in XML Test.exe

Additional information: Object reference not set to an instance of an
object.

My XML File looks like this:

<?xml version="1.0"?>
<config>
<company id="dmo">
<DefaultBranch>"02"</DefaultBranch>
<TruckSystemType>"MS"</TruckSystemType>
<TruckSystemDataDrive>"D:"</TruckSystemDataDrive>
<CompaniesOnSystem>"3"</CompaniesOnSystem>
<SalesAndServicePrinter>"P1"</SalesAndServicePrinter>
<DeliveryTicketPrinter>"P2"</DeliveryTicketPrinter>
<CounterReceiptPrinter>"P3"</CounterReceiptPrinter>
<TypeTapeBackup>"PKZ"</TypeTapeBackup>
<StatementForm>"Y"</StatementForm>
<OnePartForm>"0000"</OnePartForm>
<TwoPartForm>"0001"</TwoPartForm>
<RemotePath>"i:\rpg"</RemotePath>
<LocalPath>"c:\rpg"</LocalPath>
<CompanyEmailAddress>"te**@ss.com"</CompanyEmailAddress>
<DefaultUserName>"Master"</DefaultUserName>
<DefaultWorkstationID>"AA"</DefaultWorkstationID>
<RpgStartUpFile>"c:\rpg\gas\aastart.p"</RpgStartUpFile>
</company>
</config>

Any ideas what I am doing wrong?

Thanks!
Eroc


Jun 14 '06 #2
Actually that line is commented out, I left it there to reference what
I was suppose to code.

Anyhow you said:

za***@construction-imaging.com wrote:
I prefer parsing XML using the XMLSerializer class. Leaves all values
in nice convenient properties.


How do I go about doing that? Any info you can point me to would be
greatly appreciated.

Thanks,
Eroc

Jun 14 '06 #3

Eroc wrote:
Actually that line is commented out, I left it there to reference what
I was suppose to code.
Sorry, I didn't noticed the comment quote with the small font on my pc.

Anyhow you said:

za***@construction-imaging.com wrote:
I prefer parsing XML using the XMLSerializer class. Leaves all values
in nice convenient properties.


How do I go about doing that? Any info you can point me to would be
greatly appreciated.


This might get you started:

http://support.microsoft.com/default...;EN-US;Q314150

Jun 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
2
by: slickn_sly | last post by:
For some reason, I'm getting an error. It doesn't seem to be reading my "input.txt" file. I'm trying to read the "input.txt" file which consits of random integers and use insertion sort to sort...
3
by: Fredrik Normann | last post by:
Hello, I'm trying to read the binary files under /var/spool/rwho/ so I'm wondering if anyone has done that before or could give me some clues on how to read those files. I've tried to use the...
6
by: Dave Reid | last post by:
Hi everyone... I'm pretty much a newbie C++ user, and I've run into a problem. I'm trying to read in a large text file, and then do manipulations on it. I can read it into a large 2-dimensional...
1
by: Nasser | last post by:
Hello, I am coding a mathematical model with VC++. When I debug the code, I face with no erroe, but during executing, I face with below error "Unhandled exception at 0x0040c275 in Tar.exe:...
2
by: Kel Good | last post by:
I have a component which I want to register for COM interop. At the top of my code file I have the following lines. Imports System.Reflection <Assembly: AssemblyKeyFileAttribute("myKey.snk")>...
1
by: hzgt9b | last post by:
(FYI, using VB .NET 2003) Can someone help me with this... I'm trying to read in an XML file... it appears to work in that the DataSet ReadXML method dose not fail and then I am able to access the...
5
by: jeff | last post by:
i stated using a python module called id3reader (http://www.nedbatchelder.com/code/modules/id3reader.html) and i tried to use it to organize all my music files (right now they are all in one...
4
by: radhikams | last post by:
hi I have written a code for writing the data of a column from database into a file and again reading that file and displaying. Im writing into an .html file....Now the problem is im...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.