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

Allow user to stop the parsing process #7

Merged
merged 2 commits into from
Feb 25, 2018
Merged

Allow user to stop the parsing process #7

merged 2 commits into from
Feb 25, 2018

Conversation

qcam
Copy link
Owner

@qcam qcam commented Feb 24, 2018

This feature will be useful in case we want to stop parsing and quickly return data in the middle.

For example we are only interesting in the first <bar> tag in the underneath XML document.

<?xml version="1.0"
<foo>
  <bar bar="1st bar"/>
  <bar bar="2nd bar"/>
  <bar bar="3rd bar"/>
...
    <bar bar="nth bar"/>
</foo>

With this feature we can quit parsing and quickly return once we receive the <bar> element.

defmodule MyHandler do
  use Saxy.Handler

  def handle_event(:end_element, {"bar", attributes}, state) do
    {:stop, attributes}
  end

  def handle_event(_other_event, _, _) do
    # no need to write this actually :(
  end
end

@qcam qcam mentioned this pull request Feb 24, 2018
8 tasks
@qcam qcam merged commit a92f639 into master Feb 25, 2018
@qcam qcam deleted the control-flow branch February 25, 2018 11:10
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.

1 participant