Skip to content

Incorrect example of temporary disabling check_end_names #514

@Mingun

Description

@Mingun

The example

/// assert_eq!(reader.read_event().unwrap(), Event::Start(start));
/// // ...and disable checking of end names because we expect HTML further...
/// reader.check_end_names(false);
///
/// // ...then, we could read text content until close tag.
/// // This call will correctly handle nested <html> elements.
/// let text = reader.read_text(end.name()).unwrap();
/// assert_eq!(text, Cow::Borrowed(r#"
/// <title>This is a HTML text</title>
/// <p>Usual XML rules does not apply inside it
/// <p>For example, elements not needed to be &quot;closed&quot;
/// "#));
///
/// // Now we can enable checks again
/// reader.check_end_names(true);

for read_text is incorrect -- doing that will leave reader in incorrect state and you'll get a wrong EndEventMismatch error next time when you'll read surrounding End event:

<some-tag>
  <event>
    <!-- You decided to .check_end_names(false) after seeing "<event>" -->
    ...
  </event>
  <!-- You decided to .check_end_names(true) after seeing "</event>" -->
</some-tag><!-- EndEventMismatch { expected "event", found: "some-tag" } -->

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions