What's so bad about building XML with string concatenation?

前端 未结 12 1376
长发绾君心
长发绾君心 2020-12-01 12:21

In the thread What’s your favorite “programmer ignorance” pet peeve?, the following answer appears, with a large amount of upvotes:

Programmers who build XML u

12条回答
  •  一向
    一向 (楼主)
    2020-12-01 13:01

    As you said, it's just awkward to build XML correct using string concatenation, especially now you have XML linq that allows for simple construction of an XML graph and will get namespaces, etc correct.

    Obviously context and how it is being used matters, such as in the logging example string.Format can be perfectly acceptable.

    But too often people ignore these alternatives when working with complex XML graphs and just use a StringBuilder.

提交回复
热议问题