antchfx / xmlquery

xmlquery is Golang XPath package for XML query.
https://github.com/antchfx/xpath
MIT License
444 stars 89 forks source link

Ensure CDATA tags are preserved across parses #42

Closed heyvito closed 4 years ago

heyvito commented 4 years ago

Hi there! First, thank you for the effort on maintaining this library. Using xml.Decoder alone would be at least terrible. Since I'm using it, this is a small contribution to give back to the community.

This implements a new cachedReader that will maintain the last 4096 bytes between StartCaching and StopCaching calls. Leveraging the call sequence of xml.Decoder.Token(), we can realiably detect CDATA tags, and act accordingly. This should also work well with streams, again, given how xml.Decoder.Token() returns data. I also edited a test to ensure we maintain compatibility.

Thank you!

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.3%) to 92.079% when pulling ec55aa7cb1b118b513f1d8669e0532392e6c13b3 on heyvito:fix/cdata into def09eac03da9816386c93c73ccaf6d257138835 on antchfx:master.

zhengchun commented 4 years ago

Hello, @heyvito , Merged, thanks!

heyvito commented 4 years ago

You're mostly welcome! Thank you for creating this lib! Helped me a lot! <3

Best wishes!