Skip to content

Commit ae3542d

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 e138249 commit ae3542d

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

497497
switch (node->type) {
498+
case XML_DOCUMENT_NODE:
498499
case XML_NOTATION_NODE:
499500
case XML_DTD_NODE:
500501
case XML_ELEMENT_DECL:

Foundation/XMLNode.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,13 @@ open class XMLNode: NSObject, NSCopying {
328328
return returned == nil ? nil : unsafeBitCast(returned!, to: NSString.self) as String
329329
}
330330
set {
331-
if case .namespace = kind {
331+
switch kind {
332+
case .document:
333+
// As with Darwin, ignore the name when the node is document.
334+
break
335+
case .namespace:
332336
_CFXMLNamespaceSetPrefix(_xmlNode, newValue, Int64(newValue?.utf8.count ?? 0))
333-
} else {
337+
default:
334338
if let newName = newValue {
335339
_CFXMLNodeSetName(_xmlNode, newName)
336340
} else {

0 commit comments

Comments
 (0)