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

# comment(withStringValue:)

Returns an [`XMLNode`](/documentation/Foundation/XMLNode) object representing a comment node containing given text.

```
class func comment(withStringValue stringValue: String) -> Any
```

## Parameters

`stringValue`

A string specifying the text of the comment. You may specify `nil` or an empty string (see Return Value).

## Return Value

An [`XMLNode`](/documentation/Foundation/XMLNode) object representing an comment node ([`XMLNode.Kind.comment`](/documentation/Foundation/XMLNode/Kind-swift.enum/comment)) containing the text `stringValue` or `nil` if the object couldn’t be created. If `stringValue` is `nil` or an empty string, a content-less comment node is returned (`<!--->`).

---

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)