Skip to content

Commit

Permalink
Updates: Parsing small.xml
Browse files Browse the repository at this point in the history
instead of some hard coded xml string
  • Loading branch information
hashier committed Dec 11, 2015
1 parent 692f85b commit d7fcf18
Showing 1 changed file with 7 additions and 52 deletions.
59 changes: 7 additions & 52 deletions iOSFolket/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,57 +28,11 @@ class ViewController: UIViewController {
}

func test() {

let xmlWithNamespace = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<dictionary comment=\"generated by DictionaryTransformer\" created=\"2011-03-03\" last-changed=\"2012-08-18\" name=\"Folkets English-Swedish dictionary\" source-language=\"sv\" target-language=\"en\" version=\"1.0.213\" license=\"http://creativecommons.org/licenses/by-sa/2.5/\" licenseComment=\"Distributed under the Creative Commons Attribution-Share Alike 2.5 Generic license\" originURL=\"http://folkets-lexikon.csc.kth.se\">" +
"<word value=\"bil\" lang=\"sv\" class=\"nn\">" +
"<translation value=\"motorcar\" />" +
"<translation value=\"car\" />" +
"<translation value=\"(automobile [US])\" />" +
"<translation value=\"(auto [US])\" />" +
"<phonetic value=\"bi:l\" soundFile=\"bil.swf\" />" +
"<paradigm>" +
"<inflection value=\"bilen\" />" +
"<inflection value=\"bilar\" />" +
"</paradigm>" +
"<synonym value=\"automobil\" level=\"4.8\" />" +
"<synonym value=\"motorfordon\" level=\"3.5\" />" +
"<synonym value=\"åkdon\" level=\"3.5\" />" +
"<see value=\"bil||bil..1||bil..nn.1\" type=\"saldo\" />" +
"<example value=\"åka bil\">" +
"<translation value=\"go by car\" />" +
"</example>" +
"<compound value=\"bil|trafik\">" +
"<translation value=\"motor traffic\" />" +
"</compound>" +
"<compound value=\"lastbil\">" +
"<translation value=\"lorry, (truck [US])\" />" +
"</compound>" +
"<compound value=\"bil|sjuka\">" +
"<translation value=\"carsickness\" />" +
"</compound>" +
"<compound value=\"bil|telefon\">" +
"<translation value=\"car phone\" />" +
"</compound>" +
"<compound value=\"bil|fri\">" +
"<translation value=\"free of cars\" />" +
"</compound>" +
"<compound value=\"bil|sjuk\">" +
"<translation value=\"carsick\" />" +
"</compound>" +
"<compound value=\"personbil\">" +
"<translation value=\"passenger car\" />" +
"</compound>" +
"<compound value=\"bil|buren\">" +
"<translation value=\"motorized\" />" +
"</compound>" +
"<definition value=\"ett slags motordrivet fordon\" />" +
"<url value=\"17/bil1.swf\" type=\"any\" />" +
"<url value=\"16/stad1.swf\" type=\"any\" />" +
"</word>"

let file = NSBundle.mainBundle().pathForResource("small", ofType: "xml")
var xmlStr = try! String(contentsOfFile: file!, encoding: NSUTF8StringEncoding)

func parseDictionary(dictionary: XMLIndexer) -> [Word] {

return dictionary["word"].map(parseWord)
}

Expand All @@ -90,7 +44,9 @@ class ViewController: UIViewController {

word.value = value!
word.language = language!
word.wordClass = wordClass!
if let wordClass = wordClass {
word.wordClass = wordClass
}

for childTranslation in childWord["translation"].all {
let translation = parseTranslation(childTranslation, original: word.value)
Expand All @@ -109,12 +65,11 @@ class ViewController: UIViewController {
return translation;
}

let xml = SWXMLHash.parse(xmlWithNamespace)
let xml = SWXMLHash.parse(xmlStr)

let words = parseDictionary(xml["dictionary"])

print(words);


}

Expand Down

0 comments on commit d7fcf18

Please sign in to comment.