Skip to content

Commit 0a081c7

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 767e868 commit 0a081c7

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

488488
switch (node->type) {
489+
case XML_DOCUMENT_NODE:
489490
case XML_NOTATION_NODE:
490491
case XML_DTD_NODE:
491492
case XML_ELEMENT_DECL:

Foundation/XMLNode.swift

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

0 commit comments

Comments
 (0)