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. How do I read this XML-file?

How do I read this XML-file?

Scheduled Pinned Locked Moved C#
csharpquestionxmltutorial
3 Posts 2 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
    MaWeRic
    wrote on last edited by
    #1

    I have an XML file looking like this (just an example): <?xml version="1.0" encoding="UTF-8" ?> <family> <name xmlns="http://www.opentrans.org/XMLSchema/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" type="standard"> <firstname>Tom</firstname> <lastname>Smith</lastname> </name> <name xmlns="http://www.opentrans.org/XMLSchema/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" type="standard"> <firstname>Dale</firstname> <lastname>Smith</lastname> </name> </family> I can read up the document as a XMLDocument and navigate through SelctNodes if the Namespace attribute is not present. I have understood that I need to specify some kind of namespace using a namespace manager. This is my code so far : 'Create objcts Dim m_xmld As XmlDocument Dim m_nodelist As XmlNodeList Dim m_node As XmlNode 'Create the XML Document m_xmld = New XmlDocument() 'Load the Xml file m_xmld.Load("D:\family.xml") 'Get the list of name nodes m_nodelist = m_xmld.SelectNodes("/family/name") 'How many nodes msgbox(m_nodelist.count) Anyone can fill in the missing parts for me? C# or VB.NET .. doesn't matter Regards // M

    L 1 Reply Last reply
    0
    • M MaWeRic

      I have an XML file looking like this (just an example): <?xml version="1.0" encoding="UTF-8" ?> <family> <name xmlns="http://www.opentrans.org/XMLSchema/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" type="standard"> <firstname>Tom</firstname> <lastname>Smith</lastname> </name> <name xmlns="http://www.opentrans.org/XMLSchema/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" type="standard"> <firstname>Dale</firstname> <lastname>Smith</lastname> </name> </family> I can read up the document as a XMLDocument and navigate through SelctNodes if the Namespace attribute is not present. I have understood that I need to specify some kind of namespace using a namespace manager. This is my code so far : 'Create objcts Dim m_xmld As XmlDocument Dim m_nodelist As XmlNodeList Dim m_node As XmlNode 'Create the XML Document m_xmld = New XmlDocument() 'Load the Xml file m_xmld.Load("D:\family.xml") 'Get the list of name nodes m_nodelist = m_xmld.SelectNodes("/family/name") 'How many nodes msgbox(m_nodelist.count) Anyone can fill in the missing parts for me? C# or VB.NET .. doesn't matter Regards // M

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      In your example XML is this something you have created or been provided? Normally you wouldn't be declaring the xmlns on every node in the document.This only needs to be done once at the head of the file

      Tom
      Smith
      Dale
      Smith

      Now what you are trying to achieve when reading this file in? Just a list of name nodes and what they contain or are you trying to create objects from each node ie of Type Person as an example and then set the objects firstname/lastname properties or set said properties to instances of an object? When reading the file it would best to use the XMLReader class.

      modified on Monday, January 26, 2009 8:55 AM

      M 1 Reply Last reply
      0
      • L Lost User

        In your example XML is this something you have created or been provided? Normally you wouldn't be declaring the xmlns on every node in the document.This only needs to be done once at the head of the file

        Tom
        Smith
        Dale
        Smith

        Now what you are trying to achieve when reading this file in? Just a list of name nodes and what they contain or are you trying to create objects from each node ie of Type Person as an example and then set the objects firstname/lastname properties or set said properties to instances of an object? When reading the file it would best to use the XMLReader class.

        modified on Monday, January 26, 2009 8:55 AM

        M Offline
        M Offline
        MaWeRic
        wrote on last edited by
        #3

        It was provided that way ... I am just truing to read out the data in each name node. Right now I just use XMLdocument as seen in my code and by NodeSelect. As answered in the other forum I need to use namespace in my select to. Thanks for help .. //M

        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