Created
November 26, 2014 04:23
-
-
Save drmohundro/62d83c3910d28e49fb17 to your computer and use it in GitHub Desktop.
SWXMLHash parsing XML with namespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground - noun: a place where people can play | |
import SWXMLHash | |
import UIKit | |
let xmlWithNamespace = "<root xmlns:h=\"http://www.w3.org/TR/html4/\"" + | |
" xmlns:f=\"http://www.w3schools.com/furniture\">" + | |
" <h:table>" + | |
" <h:tr>" + | |
" <h:td>Apples</h:td>" + | |
" <h:td>Bananas</h:td>" + | |
" </h:tr>" + | |
" </h:table>" + | |
" <f:table>" + | |
" <f:name>African Coffee Table</f:name>" + | |
" <f:width>80</f:width>" + | |
" <f:length>120</f:length>" + | |
" </f:table>" + | |
"</root>" | |
var xml = SWXMLHash.parse(xmlWithNamespace) | |
// one root element | |
let count = xml["root"].all.count | |
// "Apples" | |
xml["root"]["h:table"]["h:tr"]["h:td"][0].element!.text! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment