What is the namespace method in Mojo::DOM?
Overview
The namespace method will provide the namespace for the given HTML element if it is present. This method is provided by the Mojo::DOM module, which is an HTML/XML DOM parser with CSS selectors.
Syntax
$dom->at('html element')->namespace
Return value
This method will return the namespace for the given element if it is present. Otherwise, it will return undef.
Example
use 5.010;use Mojo::DOM;# Parse the htmlmy $dom = Mojo::DOM->new('<svg xmlns:svg="http://www.w3.org/2000/svg"><svg:circle>3.14</svg:circle></svg>');# Get namespacesay $dom->at('svg\:circle')->namespace;
Explanation
- Line 2: We import the
Mojo::DOMmodule. - Line 5: We parse the HTML and store it in the
$domscalar. - Line 8: We get the namespace for the element
svg:circleusing the namespace method and print it.