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. Problem reading XML

Problem reading XML

Scheduled Pinned Locked Moved C#
databasexmlhelptutorial
4 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.
  • M Offline
    M Offline
    Mark F
    wrote on last edited by
    #1

    I have a simple xml file that displays a card file like in a Library. Each card has only one attribute, the index number. The cards are displayed in a treeview and when a use selects one I need to display the card's content in a window. The problem is that I don't know how to access a single element by referencing the attribute "number". Xml file: This is the front of card 1. This is the back of card 1. This is the front of card 2. This is the back of card 2. ... etc. Thanks, Mark

    C A 2 Replies Last reply
    0
    • M Mark F

      I have a simple xml file that displays a card file like in a Library. Each card has only one attribute, the index number. The cards are displayed in a treeview and when a use selects one I need to display the card's content in a window. The problem is that I don't know how to access a single element by referencing the attribute "number". Xml file: This is the front of card 1. This is the back of card 1. This is the front of card 2. This is the back of card 2. ... etc. Thanks, Mark

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      @ is the symbol used for attributes in an XPath. I think it's someting like "/cardfile/card[@number='0']" The W3C website has excellent XPath tutorials on it.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      M 1 Reply Last reply
      0
      • M Mark F

        I have a simple xml file that displays a card file like in a Library. Each card has only one attribute, the index number. The cards are displayed in a treeview and when a use selects one I need to display the card's content in a window. The problem is that I don't know how to access a single element by referencing the attribute "number". Xml file: This is the front of card 1. This is the back of card 1. This is the front of card 2. This is the back of card 2. ... etc. Thanks, Mark

        A Offline
        A Offline
        AFSEKI
        wrote on last edited by
        #3

        It seems you are new to XML, so I don't suggest using low-level code, there is a easy to use System.Configuration namespace out there in MSDN Library, have a look at it. 1) Create a custom ConfigurationSectionGroup called cardfile 2) Create a custom ConfigutaionSection called card number 3) Create a custom ConfigurationElementCollection to store your front(s) 4) Create a custom ConfigurationElement called front You can find all the source code examples for the steps 1->4 in MSDN library and in internet This is the link: ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref4/html/T_System_Configuration_ConfigurationElement.htm OR Look for: 1) ConfigurationElemnt class in MSDN Library Index Tab filtered by Visual C# 2) Select "about ConfigurationElement class" and there you are ;) Hope this helps...

        1 Reply Last reply
        0
        • C Christian Graus

          @ is the symbol used for attributes in an XPath. I think it's someting like "/cardfile/card[@number='0']" The W3C website has excellent XPath tutorials on it.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          M Offline
          M Offline
          Mark F
          wrote on last edited by
          #4

          Thanks for the help. I used SelectSingleNode with a path similar to the one you posted and it works fine. XPath seems to be as useful as RegEx! Mark

          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