Wrapping Arbitrary XML within XML

后端 未结 6 589
感动是毒
感动是毒 2021-01-05 07:53

I need to embed arbitrary (syntactically valid) XML documents within a wrapper XML document. The embedded documents are to be regarded as mere text, they do not need to be p

6条回答
  •  一整个雨季
    2021-01-05 08:39

    You need to properly escape the text. You don't say what language you're using, but generally: you build a DOM, create a Text node that contains your "inner" XML, and then serialize that DOM. The serializer will handle escaping for you.

    The key point here is use a serializer to produce your output. Don't simply write strings, because you're all but guaranteed to produce something that's not well-formed XML.

提交回复
热议问题