Skip to content

Spaces removed when decoding strings with escaped elements #129

@mxcl

Description

@mxcl

I am getting this kind of XML from an ancient SOAP server:

<aResponse>&lt;uesb2b:response xmlns:uesb2b=&quot;http://services.b2b.ues.ut.uhg.com/types/plans/&quot; xmlns=&quot;http://services.b2b.ues.ut.uhg.com/types/plans/&quot;&gt;&#xd;
  &lt;uesb2b:st cd=&quot;GA&quot; /&gt;&#xd;
  &lt;uesb2b:obligId val=&quot;01&quot; /&gt;&#xd;
  &lt;uesb2b:shrArrangementId val=&quot;00&quot; /&gt;&#xd;
  &lt;uesb2b:busInsType val=&quot;CG&quot; /&gt;&#xd;
  &lt;uesb2b:metalPlans typ=&quot;Array&quot;
…

When I decode with a struct like:

struct Response: Decodable {
     let aResponse: String
}

Using:

let decoder = XMLDecoder()
decoder.shouldProcessNamespaces = true
let rsp = try decoder.decode(Response.self, from: data)
print(rsp.aResponse)

I get:

<uesb2b:response xmlns:uesb2b="http://services.b2b.ues.ut.uhg.com/types/plans/"xmlns="http://services.b2b.ues.ut.uhg.com/types/plans/">
<uesb2b:st cd="GA"/>
<uesb2b:obligId val="01"/>
<uesb2b:shrArrangementId val="00"/>
<uesb2b:busInsType val="CG"/>
<uesb2b:metalPlans typ="Array"arrayTyp="metalPlan[110]">
<uesb2b:metalPlan cd="AUWJ"rx="286A"level="S"min="0"max="0"/>
<uesb2b:metalPlan cd="AUWK"rx="286A"level="G"min="0"max="0"/><uesb2b:metalPlan …

(Newlines added for legibility). You can see the spaces on either side of the &quot;s in the attribute heavy nodes are removed (last two lines).

This makes the inner XML invalid.

Happy to fix the bug, just point me at the right code, thanks.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions