Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Simplest of Things are Hard

Simplest of Things are Hard

Scheduled Pinned Locked Moved C#
questiondatabasexmlcsharpvisual-studio
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    antoine orchus tech
    wrote on last edited by
    #1

    Hi, My Question Is: with regards to XML in a C# context. For the record, I'm using VS 2002, running Win2000 dayly updated, cel400mhz,192ram,dotNET1.1 The Premices: Put simply, I am trying to use XML as a relationnal database for an application. I figured an XML schema, an XML file, and some code to plug it in and that was it. The application is to store contacts information and more types of info as we upgrade it. So what makes sense here is to have an XML file for each type of info. The user needs to be able to do the usual, such as view, add, modify, delete entries. The XML files should reside in the main application folder. Now, this is part of what I tried: -please bare in mind I'm kinda new with xml...;) The Faulty Code: string item; XmlDocument myDoc = new XmlDocument(); myDoc.Load(Application.StartupPath + "\\Contact.xml"); XmlNode myNode = myDoc.FirstChild; item = myNode.FirstChild.InnerText.ToString(); txtFirstName.Text = item; The Error Message: An unhandled exception of type 'System.NullReferenceException' occurred in Orchus_temp.exe Additional information: Object reference not set to an instance of an object. The Question Redux: " How do I add, modify, view and delete data that is stored in an XML file and rendered in a C# application? " I propose to write an article about the resolution of theses issues, since a lot of people have to resolve these kind of problems, I believe. So feel free to respond extensively as this will be the substace of my first article! :-D Thanks!:) Antoine Dubuc Montreal, Canada This by our hands that dream, "I shall find a way or make one!"

    L P 2 Replies Last reply
    0
    • A antoine orchus tech

      Hi, My Question Is: with regards to XML in a C# context. For the record, I'm using VS 2002, running Win2000 dayly updated, cel400mhz,192ram,dotNET1.1 The Premices: Put simply, I am trying to use XML as a relationnal database for an application. I figured an XML schema, an XML file, and some code to plug it in and that was it. The application is to store contacts information and more types of info as we upgrade it. So what makes sense here is to have an XML file for each type of info. The user needs to be able to do the usual, such as view, add, modify, delete entries. The XML files should reside in the main application folder. Now, this is part of what I tried: -please bare in mind I'm kinda new with xml...;) The Faulty Code: string item; XmlDocument myDoc = new XmlDocument(); myDoc.Load(Application.StartupPath + "\\Contact.xml"); XmlNode myNode = myDoc.FirstChild; item = myNode.FirstChild.InnerText.ToString(); txtFirstName.Text = item; The Error Message: An unhandled exception of type 'System.NullReferenceException' occurred in Orchus_temp.exe Additional information: Object reference not set to an instance of an object. The Question Redux: " How do I add, modify, view and delete data that is stored in an XML file and rendered in a C# application? " I propose to write an article about the resolution of theses issues, since a lot of people have to resolve these kind of problems, I believe. So feel free to respond extensively as this will be the substace of my first article! :-D Thanks!:) Antoine Dubuc Montreal, Canada This by our hands that dream, "I shall find a way or make one!"

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      You can try generate a TypedDataset from the schema :) leppie::AllocCPArticle("Zee blog");
      Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

      1 Reply Last reply
      0
      • A antoine orchus tech

        Hi, My Question Is: with regards to XML in a C# context. For the record, I'm using VS 2002, running Win2000 dayly updated, cel400mhz,192ram,dotNET1.1 The Premices: Put simply, I am trying to use XML as a relationnal database for an application. I figured an XML schema, an XML file, and some code to plug it in and that was it. The application is to store contacts information and more types of info as we upgrade it. So what makes sense here is to have an XML file for each type of info. The user needs to be able to do the usual, such as view, add, modify, delete entries. The XML files should reside in the main application folder. Now, this is part of what I tried: -please bare in mind I'm kinda new with xml...;) The Faulty Code: string item; XmlDocument myDoc = new XmlDocument(); myDoc.Load(Application.StartupPath + "\\Contact.xml"); XmlNode myNode = myDoc.FirstChild; item = myNode.FirstChild.InnerText.ToString(); txtFirstName.Text = item; The Error Message: An unhandled exception of type 'System.NullReferenceException' occurred in Orchus_temp.exe Additional information: Object reference not set to an instance of an object. The Question Redux: " How do I add, modify, view and delete data that is stored in an XML file and rendered in a C# application? " I propose to write an article about the resolution of theses issues, since a lot of people have to resolve these kind of problems, I believe. So feel free to respond extensively as this will be the substace of my first article! :-D Thanks!:) Antoine Dubuc Montreal, Canada This by our hands that dream, "I shall find a way or make one!"

        P Offline
        P Offline
        Philip Fitzsimons
        wrote on last edited by
        #3

        myDoc.FirstChild; is the problem. this is not a safe way to read an XML file - the first child could be a processing instruction... you are better of using SelectSingleNode(_xpath_); where xpath is the thing you want - in you case I'm guessing its "/contact/firstname" depending on you xml file structure...


        "When the only tool you have is a hammer, a sore thumb you will have."

        A 2 Replies Last reply
        0
        • P Philip Fitzsimons

          myDoc.FirstChild; is the problem. this is not a safe way to read an XML file - the first child could be a processing instruction... you are better of using SelectSingleNode(_xpath_); where xpath is the thing you want - in you case I'm guessing its "/contact/firstname" depending on you xml file structure...


          "When the only tool you have is a hammer, a sore thumb you will have."

          A Offline
          A Offline
          antoine orchus tech
          wrote on last edited by
          #4

          Good. Xpath is something new to me. I'll check that out and try it. thank! Antoine This by our hands that dream, "I shall find a way or make one!"

          1 Reply Last reply
          0
          • P Philip Fitzsimons

            myDoc.FirstChild; is the problem. this is not a safe way to read an XML file - the first child could be a processing instruction... you are better of using SelectSingleNode(_xpath_); where xpath is the thing you want - in you case I'm guessing its "/contact/firstname" depending on you xml file structure...


            "When the only tool you have is a hammer, a sore thumb you will have."

            A Offline
            A Offline
            antoine orchus tech
            wrote on last edited by
            #5

            Hi Phillip, Ok. So I am trying to display the firstname of the first contact in the Contact.xml file... XmlDocument myDoc = new XmlDocument(); myDoc.Load(Application.StartupPath + "\\Contact.xml"); txtfirstname.Text = myDoc.SelectSingleNode("//Contact[1]//firstname").Value; What am I missing? I am trying to find a good XPath resources, but its hard. MSDN doen't do it for me up to now. thanks :) Antoine This by our hands that dream, "I shall find a way or make one!"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups