pub fn find_depth2_element_slice_by(
body: &[u8],
predicate: impl Fn(&str) -> bool,
) -> Option<&[u8]>Expand description
Locate a depth-2 XML element (a direct child of the document root) whose
local name satisfies predicate, returning the byte slice covering it
(<El>...</El>, inclusive of tags). The document root itself is also
considered, so an “unwrapped” envelope whose root already matches is found.
Returns None if the body is not valid UTF-8, is not parseable as XML, or
contains no matching element — callers decide how to fall back.
Robust to start-tag attributes (e.g. <Error xmlns="...">), nested
same-name elements, comments, and CDATA, which a naive substring search
would mishandle. Both the AWS REST XML error path (name == "Error") and
the awsQuery response path (name.ends_with("Result") || name == "Error")
build on this.