Skip to content

Commit 82fd147

Browse files
committed
XMLNode: var name must be always nil when the node is document.
Although Libxml2's `struct _xmlDoc` has a member named `name` that indicates name/filename/URI of the document, `var name` of `XMLDocument` on Darwin returns always nil. This commit makes the behavior the same with Darwin.
1 parent a32b79f commit 82fd147

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CoreFoundation/Parsing.subproj/CFXMLInterface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ static inline xmlChar* _getQName(xmlNodePtr node) {
462462
const xmlChar* ncname = node->name;
463463

464464
switch (node->type) {
465+
case XML_DOCUMENT_NODE:
465466
case XML_NOTATION_NODE:
466467
case XML_DTD_NODE:
467468
case XML_ELEMENT_DECL:

Foundation/XMLNode.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,13 @@ open class XMLNode: NSObject, NSCopying {
321321
return _CFXMLNodeCopyName(_xmlNode)?._swiftObject
322322
}
323323
set {
324-
if case .namespace = kind {
324+
switch kind {
325+
case .document:
326+
// As with Darwin, ignore the name when the node is document.
327+
break
328+
case .namespace:
325329
_CFXMLNamespaceSetPrefix(_xmlNode, newValue, Int64(newValue?.utf8.count ?? 0))
326-
} else {
330+
default:
327331
if let newName = newValue {
328332
_CFXMLNodeSetName(_xmlNode, newName)
329333
} else {

0 commit comments

Comments
 (0)