Skip to content

Respect xml:space="preserve" (#43) #45

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

Merged
merged 4 commits into from
Jul 29, 2025

Conversation

TimG1964
Copy link
Contributor

This PR fixes the issue reported in #43. I've added extra tests, too.

One caveat in testing: I had to change one test (only):

    @testset "next and prev" begin
        @test XML.prev(doc[1]) === data

I had to change the condition from === to only ==. With this single change, tests now all pass locally.

I've also checked that this PR works well with XLSX.jl downstream and all XLSX tests also pass locally.

With this PR, XLSX now properly reads a workbook like this:
image
which has leading and trailing whitespace in column A and, in column B, only has whitespace.
Reading this XLSX file now works correctly:

julia> f=XLSX.openxlsx(raw"C:\Users\tim\OneDrive\Documents\Julia\XLSX\sstTest.xlsx", mode="rw")
XLSXFile("sstTest.xlsx") containing 1 Worksheet
            sheetname size          range        
-------------------------------------------------
               Sheet1 5x2           A1:B5        

julia> f[1][:]
5×2 Matrix{Any}:
 "  hello"    "    "
 "  hello  "  "    "
 " hello\">"  "    "
 "hello\">"   "    "
 "  hello"    "    "

Previously, leading and trailing spaces would be trimmed, and cells containing only whitespace would become missing.

I'm afraid I can't match the simple elegance of your coding style, though!

@TimG1964
Copy link
Contributor Author

Hi Josh. Is there a reason you haven't merged this? Let me know if there is anything more I need to do or if it doesn't pass muster for some reason. Thx.

@joshday
Copy link
Member

joshday commented Jul 29, 2025

Sorry for not responding!

I was in the middle of rewriting a bit of the XML internals when you made the PR and then both the rewrite and this PR got pushed to the back burner by other work.

LGTM, and again my apologies for the delay!

@joshday joshday merged commit 120038d into JuliaComputing:main Jul 29, 2025
16 checks passed
@TimG1964
Copy link
Contributor Author

Thank you! Will there be a new release?

@TimG1964 TimG1964 deleted the Preserve-whitespace branch July 29, 2025 21:37
@joshday
Copy link
Member

joshday commented Jul 29, 2025

Yes!

JuliaRegistries/General#135609

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

Successfully merging this pull request may close these issues.

2 participants