<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLElement/init(name:stringValue:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLElement(im)initWithName:stringValue:"
  },
  "title" : "init(name:stringValue:)"
}
-->

# init(name:stringValue:)

Returns an `NSXMLElement` object initialized with a specified name and a single text-node child containing a specified value.

```
convenience init(name: String, stringValue string: String?)
```

## Parameters

`name`

A string specifying the name of the element.

`string`

The string value of the receiver’s text node.

## Return Value

The initialized `NSXMLElement` object or `nil` if initialization did not succeed.

## Discussion

The string representation of this object is `<``name``>``string``</``name``>`.

---

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)