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. to read xml file

to read xml file

Scheduled Pinned Locked Moved C#
helpxmlquestion
11 Posts 6 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.
  • P P_Elza

    Hi all I posted this question yesterday also and no one replied me. I think no one is willing to help me or angry with me...... I want to read a particular node of xml file. For that i am using the code XmlTextReader reader = new XmlTextReader ("tx1.xml"); while (reader.Read ()) { if(reader.IsStartElement ()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "jid") { str=reader.ReadString(); Lblmsg.Visible=true; Lblmsg.Text="journal ID <"+ reader.Name+ "> is : "+str; reader.Read(); break; } break; } } but here the problem is it is trying to validate the xml file using the DTD. I dont want to validate it using dtd. Plz help to solve this. what i have to use here.:( Plz help me thank u

    S Offline
    S Offline
    Scott Dorman
    wrote on last edited by
    #2

    Why are you using an XmlReader? You could load the document into an XmlDocument object and then use XPath queries and SelectSingleNode or SelectNodes calls to get the node you are interested in.

    Scott.


    —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

    C P 2 Replies Last reply
    0
    • S Scott Dorman

      Why are you using an XmlReader? You could load the document into an XmlDocument object and then use XPath queries and SelectSingleNode or SelectNodes calls to get the node you are interested in.

      Scott.


      —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

      C Offline
      C Offline
      Chintan Desai
      wrote on last edited by
      #3

      Scott is absolutely correct. XPath is fastest among all in parsing xml node.

      Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)

      N 1 Reply Last reply
      0
      • C Chintan Desai

        Scott is absolutely correct. XPath is fastest among all in parsing xml node.

        Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #4

        Chintan.Desai wrote:

        Scott is absolutely correct. XPath is fastest among all in parsing xml node.

        YES he is. But if the XML file is pretty huge, then this method may take some time. I think XMLDocument class loads the entire XML file to the memory when it initializes. Am I right ?


        My Website | Ask smart questions

        S C 2 Replies Last reply
        0
        • S Scott Dorman

          Why are you using an XmlReader? You could load the document into an XmlDocument object and then use XPath queries and SelectSingleNode or SelectNodes calls to get the node you are interested in.

          Scott.


          —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

          P Offline
          P Offline
          P_Elza
          wrote on last edited by
          #5

          I want to read a huge xml file and the node that i want to read is about to the middle of the file. Then also XPath is of to use?

          N S S J 4 Replies Last reply
          0
          • P P_Elza

            I want to read a huge xml file and the node that i want to read is about to the middle of the file. Then also XPath is of to use?

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #6

            P_Elza wrote:

            I want to read a huge xml file and the node that i want to read is about to the middle of the file. Then also XPath is of to use?

            Why don't you write an application that compares performance difference for both the methods. I feel loading huge XML file to XMlDocument class will be slow compared to other.


            My Website | Ask smart questions

            1 Reply Last reply
            0
            • N N a v a n e e t h

              Chintan.Desai wrote:

              Scott is absolutely correct. XPath is fastest among all in parsing xml node.

              YES he is. But if the XML file is pretty huge, then this method may take some time. I think XMLDocument class loads the entire XML file to the memory when it initializes. Am I right ?


              My Website | Ask smart questions

              S Offline
              S Offline
              Scott Dorman
              wrote on last edited by
              #7

              Yes, you are correct. The XmlDocument class does read the entire file into memory. In my opinion, if you're trying to deal with XML files that large, you should probably be using something other than XML.

              Scott.


              —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

              1 Reply Last reply
              0
              • P P_Elza

                I want to read a huge xml file and the node that i want to read is about to the middle of the file. Then also XPath is of to use?

                S Offline
                S Offline
                Scott Dorman
                wrote on last edited by
                #8

                Yes, XPath would be of use. XPath is the "query" language that allows you to retrieve a specific node or list of nodes. Think of it as working in a similar way to a SQL Select statement for a database.

                Scott.


                —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

                1 Reply Last reply
                0
                • P P_Elza

                  I want to read a huge xml file and the node that i want to read is about to the middle of the file. Then also XPath is of to use?

                  S Offline
                  S Offline
                  Sandeep Akhare
                  wrote on last edited by
                  #9

                  What is the size of your xml file ? if its 1 GB like that then you hsould use xmlreader and dom in hand like this http://www.codeproject.com/useritems/XmlParsing.asp[^]

                  Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                  1 Reply Last reply
                  0
                  • N N a v a n e e t h

                    Chintan.Desai wrote:

                    Scott is absolutely correct. XPath is fastest among all in parsing xml node.

                    YES he is. But if the XML file is pretty huge, then this method may take some time. I think XMLDocument class loads the entire XML file to the memory when it initializes. Am I right ?


                    My Website | Ask smart questions

                    C Offline
                    C Offline
                    Chintan Desai
                    wrote on last edited by
                    #10

                    ya, u r correct? but buddy loading xml and parsing both are completely different. Its work of different object. Its just lik this Building apartement is made by engineer, but its maintainance is depend on people who live ther. So, XPath is very fastest in parsing. Bye

                    Regards Chintan www.visharadsoft.com (I am thinking to change humans to computer, but unfortunately GOD will not give me the source code)

                    1 Reply Last reply
                    0
                    • P P_Elza

                      I want to read a huge xml file and the node that i want to read is about to the middle of the file. Then also XPath is of to use?

                      J Offline
                      J Offline
                      Jimmy Zhang
                      wrote on last edited by
                      #11

                      You may want to take a look at vtd-xml for that... http://vtd-xml.sf.net

                      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