Skip to content

Commit 9b21f62

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 11b14d7 commit 9b21f62

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
@@ -459,6 +459,7 @@ static inline xmlChar* _getQName(xmlNodePtr node) {
459459
const xmlChar* ncname = node->name;
460460

461461
switch (node->type) {
462+
case XML_DOCUMENT_NODE:
462463
case XML_NOTATION_NODE:
463464
case XML_DTD_NODE:
464465
case XML_ELEMENT_DECL:

Foundation/XMLNode.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,13 @@ open class XMLNode: NSObject, NSCopying {
312312
return _CFXMLNodeCopyName(_xmlNode)?._swiftObject
313313
}
314314
set {
315-
if case .namespace = kind {
315+
switch kind {
316+
case .document:
317+
// As with Darwin, ignore the name when the node is document.
318+
break
319+
case .namespace:
316320
_CFXMLNamespaceSetPrefix(_xmlNode, newValue, Int64(newValue?.utf8.count ?? 0))
317-
} else {
321+
default:
318322
if let newName = newValue {
319323
_CFXMLNodeSetName(_xmlNode, newName)
320324
} else {

0 commit comments

Comments
 (0)