XML message generation

This is a discussion on XML message generation within the C# Programming forums, part of the General Programming Boards category; Hello everyone, I need to generate some XML message, but the message can not be reflected from members or properties ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    XML message generation

    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

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Use XmlDocument/XmlElement instead of StringBuilder perhaps ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks nvoigt,


    1.

    I read some documents for XMLDocument and XMLElement, looks like we need to use DOM model, right?

    2.

    I have not found some good samples for a beginner, I have XML knowledge before and just want to learn how to use the C# classes. Any referred samples?

    Quote Originally Posted by nvoigt View Post
    Use XmlDocument/XmlElement instead of StringBuilder perhaps ?

    regards,
    George

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Look up System.Xml.XmlWriter as it has some neat features, like buildt-in indentation. Either build up an XmlDocument and save it to the writer, or write each node yourself manually. Either way works, and can even be combined to some extent.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Quote Originally Posted by George2 View Post
    I have not found some good samples for a beginner, I have XML knowledge before and just want to learn how to use the C# classes. Any referred samples?
    http://www.google.de/search?q=XMLDocument+XMLElement

    http://www.google.de/search?q=c%23+X...lement+example

    First link for both looks fine to me.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Great Magos!


    Any pros and cons compared with XMLTextWriter and XMLDocument from functional and performance perspective?

    Quote Originally Posted by Magos View Post
    Look up System.Xml.XmlWriter as it has some neat features, like buildt-in indentation. Either build up an XmlDocument and save it to the writer, or write each node yourself manually. Either way works, and can even be combined to some extent.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 01:22 AM
  4. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21