Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode Characters #25

Closed
NIESolutions opened this issue Oct 24, 2018 · 2 comments
Closed

Unicode Characters #25

NIESolutions opened this issue Oct 24, 2018 · 2 comments

Comments

@NIESolutions
Copy link

NIESolutions commented Oct 24, 2018

While using SwiftyXMLParser with a string with unicode characters inside, the parser automatically stops at the (probably) unknown message.

Inside Message was something like this:
<xmlopening>@ß123\u{1c}</xmlopening>

I think the \u{1c} is a character caused by application / data transfer error.

After this line in file, the rest of XML will be ignored.

@kazuhiro4949
Copy link
Member

kazuhiro4949 commented Nov 4, 2018

@NIESolutions
I'm sorry for my late.

XMLParser cannot parse '\u{1c}', because it is invalid as XML Document. Refer to the link.

https://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0

You have to escape them with percent encoding to make a valid XML document.

let str2 = "<xmlopening>@ß123\u{1c}</xmlopening>"
    .addingPercentEncoding(withAllowedCharacters: CharacterSet.controlCharacters.inverted)
let xml = try! XML.parse(str2!)
print(xml["xmlopening"].text!.removingPercentEncoding!) // -> "@ß123\u{1C}"

@kazuhiro4949
Copy link
Member

I updated this library to support the invalid character error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants