drmohundro / SWXMLHash

Simple XML parsing in Swift
MIT License
1.4k stars 203 forks source link

SWXMLHash.parse(data) not complete #228

Closed pandapancake closed 4 years ago

pandapancake commented 4 years ago

So one of the function I have in my app is merging two XML files by uploading it to the server. Then the server will return it back with one combined XML file with one string value between two XML files.

Return from the server:

<xml one>
   ... 
         </xml one>xxxEHRxxx<xml two>
   ...
</xml two>

As the example thexxxEHRxxx is the string value. My problem is when I do String(bytes: data, encoding: .utf8)thexxxEHRxxxand <xml two> are showing but not with SWXMLHash.parse(data). It will only show the XML before the string part. What can I do to let the full combined XML show? Thank you.

pandapancake commented 4 years ago

I end up putting the <xml two> inside the<xml one> and is working. Just not sure why it is not showing even when I remove the xxxEHRxxx.

drmohundro commented 4 years ago

The issue I think is that it isn't well structured XML. For example, this isn't valid XML because you have to have a single root element:

<xml-one>...</xml-one><xml-two>...</xml-two>

This would be, though:

<root><xml-one>...</xml-one><xml-two>...</xml-two></root>

SWXMLHash will do its best, but if the XML content isn't valid XML, it can't necessarily parse everything. If you're trying to combine two XML documents, I'd wrap the two of them in another <root> element or something like that first.

Hope this helps!

pandapancake commented 4 years ago

Ok Thanks! I know what to do now!