|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reading XML file getting erroron 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"> Show quoteHide quote <DefaultBranch>"02"</DefaultBranch> </company><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>"t***@ss.com"</CompanyEmailAddress> <DefaultUserName>"Master"</DefaultUserName> <DefaultWorkstationID>"AA"</DefaultWorkstationID> <RpgStartUpFile>"c:\rpg\gas\aastart.p"</RpgStartUpFile> </config> Any ideas what I am doing wrong? Thanks! Eroc Eroc wrote:
Show quoteHide quote > I'm new to XML files so I'm kinda lost here. I found some example code This appears to be part of the problem. Looks like you have the 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) 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. Show quoteHide quote > > > 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>"t***@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 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 How do I go about doing that? Any info you can point me to would be> in nice convenient properties. greatly appreciated. Thanks, Eroc Eroc wrote:
> Actually that line is commented out, I left it there to reference what Sorry, I didn't noticed the comment quote with the small font on my pc.> I was suppose to code. > This might get you started:> 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. http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q314150
Undefined function 'InStrRev' in expression.
Is this Possible ? The big Debate on DoEvents How to easily create useful data-entry forms in vb.net? Array Problems - still cant get something set up right. Dll fails to register Click and Double click events are not fired in listview component in VB.NET How can I get Windows user, password and domain? How to override only Get or only Set? where shoule store the questions and answers |
|||||||||||||||||||||||