We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If the root of the XML document has a default xmlns namespace definition, then XMLElement.attribute(forName:) will incorrectly return nil.
XMLElement.attribute(forName:)
nil
<?xml version="1.0" encoding="utf-8"?> <AppInstaller Version="99.99.99.100" xmlns="http://schemas.microsoft.com/appx/appinstaller/2018"> <MainPackage Version="99.99.99.100"/> </AppInstaller>
let xmlFile = "file:///c:/temp/foo.xml" let doc = try XMLDocument(contentsOf: URL(fileURLWithPath: xmlFile)!) let mainPackage = doc.rootElement()!.elements(forName: "MainPackage")[0] print(mainPackage.attribute(forName: "Version"))
swift run
Console prints Optional( Version="99.99.99.100")
Optional( Version="99.99.99.100")
Console prints nil
xmlns="http://schemas.microsoft.com/appx/appinstaller/2018"
private extension XMLElement { func knownAttributeValue(forName: String) -> String { for attribute in attributes ?? [] { guard forName == attribute.name, let value = attribute.stringValue else { continue } return value } fatalError("No attribute named \(forName) found") } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
If the root of the XML document has a default xmlns namespace definition, then
XMLElement.attribute(forName:)
will incorrectly returnnil
.Repro steps
swift run
the projectExpected
Console prints
Optional( Version="99.99.99.100")
Actual
Console prints
nil
Other Notes
xmlns="http://schemas.microsoft.com/appx/appinstaller/2018"
from the root doc makes things work as expected.The text was updated successfully, but these errors were encountered: