## XML DOM Element namespaceURI Property
The `namespaceURI` property returns the namespace Uniform Resource Identifier (URI) of the selected element.
In XML documents, namespaces are used to avoid naming conflicts when different XML documents share the same element names. The `namespaceURI` property allows you to programmatically retrieve this identifier.
---
## Definition and Usage
* The `namespaceURI` property returns a string representing the namespace URI of the element.
* If the element does not have a namespace, or if the node is not an element or attribute, this property returns `null` (or `undefined` in some environments).
* This property is **read-only**.
---
## Syntax
```javascript
elementNode.namespaceURI
```
### Return Value
* **String**: The namespace URI of the node.
* **Null**: If no namespace is specified for the node.
---
## Code Example
The following example demonstrates how to retrieve the namespace URI of an element.
Suppose we have an XML file named `books_ns.xml` with the following content:
```xml
The Hobbit
```
We can load this XML document and retrieve the namespace URI of the `
` element using the following JavaScript code:
```javascript
// Load the XML document
var xmlDoc = loadXMLDoc("books_ns.xml");
// Get the first element
var x = xmlDoc.getElementsByTagName("title");
// Output the namespace URI of the element
document.write("Namespace URI: " + x.namespaceURI);
```
### Output
```text
Namespace URI: https://www.youtip.co/fictional/
```
---
## Technical Considerations & Best Practices
### 1. Namespace Inheritance
If an element does not have an explicit prefix but is nested inside a parent element with a default namespace (e.g., `xmlns="http://www.w3.org/1999/xhtml"`), it inherits that default namespace. In this case, `namespaceURI` will return the inherited URI rather than `null`.
### 2. HTML5 vs. XML/XHTML
* In standard **HTML5** documents, elements like ``, `
`, and `
` are automatically assigned the XHTML namespace URI: `http://www.w3.org/1999/xhtml`.
* SVG elements in an HTML document will return `http://www.w3.org/2000/svg`.
* MathML elements will return `http://www.w3.org/1998/Math/MathML`.
### 3. Read-Only Property
You cannot change an element's namespace by assigning a new value to `namespaceURI`. To create an element with a specific namespace, you must use the `document.createElementNS()` method:
```javascript
// Create a new element with a specific namespace
var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
console.log(svgElement.namespaceURI); // Outputs: http://www.w3.org/2000/svg
```