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. XML message generation

XML message generation

Scheduled Pinned Locked Moved C#
xmlquestion
19 Posts 4 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.
  • N N a v a n e e t h

    George_George wrote:

    looks like we need to use DOM model, right?

    Yes. XMLDocument use DOM. When file is loaded, it loads the entire file into memory. So if the file is very large, this method is inefficient. Calling Save() method on this class instance will save all the changes made to the instance.

    George_George wrote:

    Any referred samples?

    I think MSDN has enough documentation on using these classes. It's pretty easy.

    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

    G Offline
    G Offline
    George_George
    wrote on last edited by
    #7

    Thanks N a v a n e e t h, XMLTextWriter will not use DOM model and only loads necessary nodes other than all nodes (which is done in DOM model)? regards, George

    N 1 Reply Last reply
    0
    • G George_George

      Thanks N a v a n e e t h, XMLTextWriter will not use DOM model and only loads necessary nodes other than all nodes (which is done in DOM model)? regards, George

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

      George_George wrote:

      XMLTextWriter will not use DOM model and only loads necessary nodes other than all nodes

      XMLTextWriter won't load any nodes. It is used to create XML documents. It has some methods which you can use to create nodes, attributes etc.

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

      G 1 Reply Last reply
      0
      • G George_George

        Hello everyone, I need to generate some XML message, but the message can not be reflected from members or properties of class instance directly. Currently, I am using StringBuilder to append strings into XML message manually (e.g. to generate the element's hierarchies and add attributes to element), I think this method is stupid. Any better approaches recommended? thanks in advance, George

        V Offline
        V Offline
        vytheese
        wrote on last edited by
        #9

        If your using .NET 3.5 Try to use XElement using System.Xml.Linq its pretty easy, fast and convinient when compared to DOM

        Regards, Vythees Miles to go before sleep...

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

          George_George wrote:

          XMLTextWriter will not use DOM model and only loads necessary nodes other than all nodes

          XMLTextWriter won't load any nodes. It is used to create XML documents. It has some methods which you can use to create nodes, attributes etc.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

          G Offline
          G Offline
          George_George
          wrote on last edited by
          #10

          Sorry, N a v a n e e t h! My bad, I mean XMLTextReader, it will not load the entire tree as DOM, like XMLDocument, and it will only loads necessary nodes, right? regards, George

          N 1 Reply Last reply
          0
          • V vytheese

            If your using .NET 3.5 Try to use XElement using System.Xml.Linq its pretty easy, fast and convinient when compared to DOM

            Regards, Vythees Miles to go before sleep...

            G Offline
            G Offline
            George_George
            wrote on last edited by
            #11

            Thanks Vythees, I need to use .Net 2.0 in current project, do you have any suggestions? regards, George

            V 1 Reply Last reply
            0
            • G George_George

              Sorry, N a v a n e e t h! My bad, I mean XMLTextReader, it will not load the entire tree as DOM, like XMLDocument, and it will only loads necessary nodes, right? regards, George

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

              Yes. It will not load the full file initially. XMLDocument class is also using a reader internally to fill the data.

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

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

                Yes. It will not load the full file initially. XMLDocument class is also using a reader internally to fill the data.

                All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                G Offline
                G Offline
                George_George
                wrote on last edited by
                #13

                Thanks N a v a n e e t h, 1. So, can I understand that using XMLDocument has better performance compared with XMLTextReader, but bigger memory footprint. 2. XMLDocument can both read/write, but XMLTextReader can only read, and XMLTextWriter can only write? regards, George

                N 1 Reply Last reply
                0
                • G George_George

                  Thanks N a v a n e e t h, 1. So, can I understand that using XMLDocument has better performance compared with XMLTextReader, but bigger memory footprint. 2. XMLDocument can both read/write, but XMLTextReader can only read, and XMLTextWriter can only write? regards, George

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

                  George_George wrote:

                  So, can I understand that using XMLDocument has better performance compared with XMLTextReader, but bigger memory footprint.

                  This depends on the XML file size. When you call Load() method in an XMLDocument classes instance, it reads all the nodes and forms a DOM and keeps in the memory. So when the file is huge, it will consume more memory. Performance is dependent of your scenario. If you need to read the XMLFile (not as DOM), XMLTextReader will give good performance. For creating a new xml file, XMLTextWriter will give good performance. Say, in a situation where you will add new nodes, change the attributes, and doing some XPath queries, then better choice would be XMLDocument class.

                  George_George wrote:

                  XMLDocument can both read/write, but XMLTextReader can only read, and XMLTextWriter can only write?

                  XMLDocument class can do more than read/write. It supports XPath queries also.

                  All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

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

                    George_George wrote:

                    So, can I understand that using XMLDocument has better performance compared with XMLTextReader, but bigger memory footprint.

                    This depends on the XML file size. When you call Load() method in an XMLDocument classes instance, it reads all the nodes and forms a DOM and keeps in the memory. So when the file is huge, it will consume more memory. Performance is dependent of your scenario. If you need to read the XMLFile (not as DOM), XMLTextReader will give good performance. For creating a new xml file, XMLTextWriter will give good performance. Say, in a situation where you will add new nodes, change the attributes, and doing some XPath queries, then better choice would be XMLDocument class.

                    George_George wrote:

                    XMLDocument can both read/write, but XMLTextReader can only read, and XMLTextWriter can only write?

                    XMLDocument class can do more than read/write. It supports XPath queries also.

                    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                    G Offline
                    G Offline
                    George_George
                    wrote on last edited by
                    #15

                    Great N a v a n e e t h! If I only need to read XML documents (in a file) into memory and get some values for some elements, then I think using XMLDocument will always have better performance, since all nodes are in memory (compared with XMLTextReader, only parts of nodes are in memory). Why do you think it is not always true? regards, George

                    N 1 Reply Last reply
                    0
                    • G George_George

                      Great N a v a n e e t h! If I only need to read XML documents (in a file) into memory and get some values for some elements, then I think using XMLDocument will always have better performance, since all nodes are in memory (compared with XMLTextReader, only parts of nodes are in memory). Why do you think it is not always true? regards, George

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

                      George_George wrote:

                      If I only need to read XML documents (in a file) into memory and get some values for some elements, then I think using XMLDocument will always have better performance

                      If the file size is less, you won't find any performance differences. XMLDocument provides an easy way to load and edit data. You can go with any methods which really suits your scenario.

                      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

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

                        George_George wrote:

                        If I only need to read XML documents (in a file) into memory and get some values for some elements, then I think using XMLDocument will always have better performance

                        If the file size is less, you won't find any performance differences. XMLDocument provides an easy way to load and edit data. You can go with any methods which really suits your scenario.

                        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                        G Offline
                        G Offline
                        George_George
                        wrote on last edited by
                        #17

                        Thanks N a v a n e e t h, If the size of file is big, using XMLDocument is of better performance? :-) regards, George

                        1 Reply Last reply
                        0
                        • G George_George

                          Thanks Vythees, I need to use .Net 2.0 in current project, do you have any suggestions? regards, George

                          V Offline
                          V Offline
                          vytheese
                          wrote on last edited by
                          #18

                          Go for XMLDocument since its easy to maintain, futuristic, and supports XPath queries.

                          Regards, Vythees Miles to go before sleep...

                          G 1 Reply Last reply
                          0
                          • V vytheese

                            Go for XMLDocument since its easy to maintain, futuristic, and supports XPath queries.

                            Regards, Vythees Miles to go before sleep...

                            G Offline
                            G Offline
                            George_George
                            wrote on last edited by
                            #19

                            Thanks Vythees, What do you think the pros and cons compared with XMLDocument and XMLTextWriter from functional and performance perspective? regards, George

                            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