Could anyone please provide XPath expression which selects all nodes that have explicit ‘xmlns’ attribute, e.g. <html xmlns="http://www.w3.org/1999/xhtml">? //*[@xmlns] does not work because (as it turned out) xmlns is not treated as attribute by XPath.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>Информация по счетам, картам</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="pragma" content="no-cache"/>
.......
I need only ‘html’ node here.
The technically correct answer is that it’s…
Not possible. You need to distinguish between the abstract document that the source text represents and the actual source text itself. XPath operates on the abstraction, not on the source text, and the location of the
xmlnspseudo-attribute is only relevant in the latter.However…
You could sort of fake it with the following XPath 2.0 expression:
This selects any element that does not have an ancestor in the same namespace, which theoretically means that it selects all elements where the namespace is declared. However, it won’t catch namespaces that are re-declared. For example, consider this document:
The expression above selects the
htmlelement and the firstp. The secondphas an ancestor in the same namespace, so it’s not selected, even though it specifies anxmlns.