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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim query As String
Dim Node As XmlNode
Dim sReturnedValue As String
'Add any initialization after the InitializeCompo nent() call
configFileName = "i:\rpg\configs \config2.xml"
document = New XmlDocument
document.Load(c onfigFileName)
query = "descendant::co mpany[@id='dmo']"
Node = document.Docume ntElement.Selec tSingleNode(que ry)
'("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.NullRef erenceException ' 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>
<TruckSystemTyp e>"MS"</TruckSystemType >
<TruckSystemDat aDrive>"D:"</TruckSystemData Drive>
<CompaniesOnSys tem>"3"</CompaniesOnSyst em>
<SalesAndServic ePrinter>"P1"</SalesAndService Printer>
<DeliveryTicket Printer>"P2"</DeliveryTicketP rinter>
<CounterReceipt Printer>"P3"</CounterReceiptP rinter>
<TypeTapeBackup >"PKZ"</TypeTapeBackup>
<StatementForm> "Y"</StatementForm>
<OnePartForm>"0 000"</OnePartForm>
<TwoPartForm>"0 001"</TwoPartForm>
<RemotePath>"i: \rpg"</RemotePath>
<LocalPath>"c:\ rpg"</LocalPath>
<CompanyEmailAd dress>"test@ss. com"</CompanyEmailAdd ress>
<DefaultUserNam e>"Master"</DefaultUserName >
<DefaultWorksta tionID>"AA"</DefaultWorkstat ionID>
<RpgStartUpFile >"c:\rpg\gas\aa start.p"</RpgStartUpFile>
</company>
</config>
Any ideas what I am doing wrong?
Thanks!
Eroc
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim query As String
Dim Node As XmlNode
Dim sReturnedValue As String
'Add any initialization after the InitializeCompo nent() call
configFileName = "i:\rpg\configs \config2.xml"
document = New XmlDocument
document.Load(c onfigFileName)
query = "descendant::co mpany[@id='dmo']"
Node = document.Docume ntElement.Selec tSingleNode(que ry)
'("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.NullRef erenceException ' 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>
<TruckSystemTyp e>"MS"</TruckSystemType >
<TruckSystemDat aDrive>"D:"</TruckSystemData Drive>
<CompaniesOnSys tem>"3"</CompaniesOnSyst em>
<SalesAndServic ePrinter>"P1"</SalesAndService Printer>
<DeliveryTicket Printer>"P2"</DeliveryTicketP rinter>
<CounterReceipt Printer>"P3"</CounterReceiptP rinter>
<TypeTapeBackup >"PKZ"</TypeTapeBackup>
<StatementForm> "Y"</StatementForm>
<OnePartForm>"0 000"</OnePartForm>
<TwoPartForm>"0 001"</TwoPartForm>
<RemotePath>"i: \rpg"</RemotePath>
<LocalPath>"c:\ rpg"</LocalPath>
<CompanyEmailAd dress>"test@ss. com"</CompanyEmailAdd ress>
<DefaultUserNam e>"Master"</DefaultUserName >
<DefaultWorksta tionID>"AA"</DefaultWorkstat ionID>
<RpgStartUpFile >"c:\rpg\gas\aa start.p"</RpgStartUpFile>
</company>
</config>
Any ideas what I am doing wrong?
Thanks!
Eroc
Comment