<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLNode/namespace(withName:stringValue:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLNode(cm)namespaceWithName:stringValue:"
  },
  "title" : "namespace(withName:stringValue:)"
}
-->

# namespace(withName:stringValue:)

Returns an `NSXMLNode` object representing a namespace with a specified name and URI.

```
class func namespace(withName name: String, stringValue: String) -> Any
```

## Parameters

`name`

A string that is the name of the namespace. Specify an empty string for `name` to get the default namespace.

`stringValue`

A string that identifies the URI associated with the namespace.

## Return Value

An `NSXMLNode` object of kind [`XMLNode.Kind.namespace`](/documentation/Foundation/XMLNode/Kind-swift.enum/namespace) or `nil` if the object couldn’t be created.

## Discussion

The equivalent namespace declaration in XML markup is `xmlns:``name``="``value``"`.

### Special Considerations

Applications linked on macOS 10.6 or later will throw an exception if the `name` parameter is `nil`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)