I created XML parsing logic that forces XML to be formatted like this:
<fooList>
<fooObject value="SomeValue1" />
<fooObject value="SomeValue2" />
</fooList>
And then I started to think that a more elegant way would be
<fooList>
<fooObject>SomeValue1</fooObject>
<fooObject>SomeValue2</fooObject>
</fooList>
Are there any recommendations or good practices regarding this? I already know about Element vs. Attribute question, please note that mine is different.
[SomeValue1]
now may have problems if it has&
, or quotes,<>
or newlines... Not that it cannot be solved, but you lost the flexibility of just using aCDATA
item and dump whatever you want in there. – SJuan76 Sep 05 '14 at 15:11]]>
(i.e. a CDATA section terminator). Properly escaping all output is the only robust option when creating XML or HTML files. Escaping the characters&'"<>
really isn't that hard. – amon Sep 05 '14 at 15:21]]>
substring by ending and restarting the section halfway through the string – ratchet freak Sep 05 '14 at 16:12