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

Add Nokogiri::XML::SAX::ParserContext#recovery #453

Merged
merged 2 commits into from
Nov 13, 2013

Conversation

libc
Copy link
Contributor

@libc libc commented May 5, 2011

Hi guys,

This pull request adds an optional ability to recover from structural errors. Sometimes it's useful. I don't change the default value (which is false).

For example,

xml = <<-eoxml
<?xml version="1.0" ?><Root><Data><?xml version='1.0'?><Item>hey</Item></Data><Data><Item>hey yourself</Item></Data></Root>
eoxml

class Doc < Nokogiri::XML::SAX::Document
  def start_element(name, attributes)
    puts "<#{name}>"
  end

  def end_element(name)
    puts "</#{name}>"
  end

  def characters(string)
    puts string
  end
end

parser = Nokogiri::XML::SAX::Parser.new(Doc.new)
parser.parse(xml) do |ctx|
  ctx.recovery = false
end

When recovery is true

<Root>
<Data>
<Item>
hey
</Item>
</Data>
<Data>
<Item>
hey yourself
</Item>
</Data>
</Root>

When recovery is false

<Root>
<Data>
hey
hey yourself

Cheers,
Eugene Pimenov

…er from fatal errors (such as spurious <?xml?> in the middle of the document).
@kingcu
Copy link

kingcu commented Jul 20, 2011

This is great! I had this on my todo list for a few months now. It would be awesome to see this make it upstream.

@jvshahid
Copy link
Member

@flavorjones this looks good to me, any objection to merging this in ?

jvshahid added a commit that referenced this pull request Nov 13, 2013
Add Nokogiri::XML::SAX::ParserContext#recovery
@jvshahid jvshahid merged commit 4b7a7fb into sparklemotion:master Nov 13, 2013
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.

3 participants