drmohundro / SWXMLHash

Simple XML parsing in Swift
MIT License
1.41k stars 205 forks source link

Can't parse values with "&" characters #192

Closed reimond closed 6 years ago

reimond commented 6 years ago

After a while using it, I have realised that I can't get values with escaping values.

The xml response looks like

let xmlResponseString = "<TrackList><Entry><Id>2</Id><Uri>/Input/E21u</Uri><Metadata><DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><item id="E21"><dc:title>Doing It To Death</dc:title><upnp:album>Ash & Ice</upnp:album><upnp:artist>The Kills</upnp:artist><upnp:class>object.item.audioItem.musicTrack</upnp:class><upnp:albumArtURI>http://192.168.1.106:8088/storage/emulated/0/record_cache/album_art/1535461905688.jpg</upnp:albumArtURI><res sampleFrequency="96000" bitsPerSample="24" bitrate="2304000" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg" duration="00:04:07.431">/Input/E21</res></item></DIDL-Lite></Metadata></Entry></TrackList>"

In the response the album name is equal to "Ash & Ice". However the value returned is "Ash "

That is how I get the value:

let xmlHash = SWXMLHash.parse(xmlResponseString)
albumName = xmlHash["DIDL-Lite"]["item"]["upnp:album"].element?.text

Furthermore, inspecting "xmlHash" it looks like the error already comes from "SWXMLHash.parse(xmlResponseString)".

drmohundro commented 6 years ago

Hi @reimond - check out #109 where a similar question was brought up. & isn't valid XML unless it is placed in a CDATA section. Otherwise, it would need to be escaped.

drmohundro commented 6 years ago

Closing as I saw you were able to get an answer at https://stackoverflow.com/questions/52072583/drmohundro-swxmlhash-and-escaping-values-in-swift.