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

Support for xml:space="preserve" #51

Closed
xavier opened this issue Dec 8, 2019 · 1 comment · Fixed by #52
Closed

Support for xml:space="preserve" #51

xavier opened this issue Dec 8, 2019 · 1 comment · Fixed by #52

Comments

@xavier
Copy link

xavier commented Dec 8, 2019

It appears that Saxy doesn't support the xml:space="preserve" attribute and fails to emit character data for an element containing only whitespace.

Here's a test which illustrates the issue and the expected behavior:

test "parses elements with xml:space=\"preserve\"" do
  buffer = "<foo xml:space=\"preserve\">   </foo>"

  assert {:ok, state} = parse(buffer)
  events = Enum.reverse(state.user_state)

  assert [{:start_element, {"foo", [{"xml:space", "preserve"}]}} | events] = events
  assert [{:characters, "   "} | events] = events
  assert [{:end_element, "foo"} | events] = events
  assert [{:end_document, {}} | events] = events

  assert events == []
end

Note that this is a trivial case as the behavior dictated by xml:space is supposed to be inherited by child nodes.

I had a look at parser/element.ex and it seems like supporting such stateful behavior might be challenging.
Perhaps could we work around the issue by allowing some level of customization of whitespace handling as an option to the parse functions?

@qcam
Copy link
Owner

qcam commented Dec 9, 2019

Thanks for the report! It seems like it's a bug if Saxy doesn't emit the :characters event for this case. White spaces won't be trimmed by the parser and it's up to the application to decide what to do with it.

I will take a look into this.

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 a pull request may close this issue.

2 participants