قالب وردپرس درنا توس
Home / IOS Development / ios – Pars a specific tag and save as String with XMLParser in Swift

ios – Pars a specific tag and save as String with XMLParser in Swift



I will analyze the answers below and just save the value of the "pdf info" tag as a string,

  la serverResponse = " n  n   n  n  n  n  n t [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n]  n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n 
 n  n  Av   by  of   t  by   n   t t  n  Man  n  n  Man  t [n] [n]  t  t  t  t  t  t  t [N] [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] ] [n]  n  n  n  n  n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n t [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] t  n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n ] [n] [n] [n] [n] [n] 1 9459095]  t  t  t  t  t  t  t  t n [n] [n] n [n] n [n] n [n] n [n] n [n]  n [n] n [n] n [n] n [n] n [n] n [n] n t [n] n [n] n [n]  t  t  t t [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] [n] [n] n [n] n [n] n [n]  t  n [n] n [n] n [n] n [n] n [n] n t  n [n]  t  t  t  t   n [n] n [n] n [n] n [n] n [n] n [n] n t [n] n  n  n  n n [n] n [n] n [n] n [n] n [n] n [n] n t   n  n  n  n  n  n ] [n]  n  [n]  n  n n [n] n [n] n [n] n [n] n   n n  n  n  n  n  n n [n] n  n  n  n  n  n t  n  n  n  n  n  Av  n  n  n  Ja  n   n  Av  n  n  n  n  n  Av  n  n  n  Off  t  n [n]  n  n  n  n  n  n [n] n  n  n  n  n  n 

I tried with the subcode,

  la recordKey = "xfdf"
was currentValue: String?

private services: [PDFInfo] = []
private was foundedService: PDFInfo?
private was activeElement: String?

if let formData = serverResponse {
la parser = XMLParser (data: Data (formData.utf8))
parser.delegate = self
if parser.parse () {
print (self.services)
}
}

extension ViewController: XMLParserDelegate {
// initialize the result structure
func parserDidStartDocument (_ parser: XMLParser) {
currentValue = ""
}

func parser (_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
whose elementName == recordKey {
foundedService = PDFInfo (info: "")
}
activeElement = elementName
}

// found characters
//
// - If this is an item we care about, add these characters.
// - If `currentValue` is still` nil`, do nothing.

func parser (_ parser: XMLParser, foundCharacters string: String) {
current value? + = string
change activeElement {
thing "pdf-info": foundedService? .info = strict
default: pause
}
}

// element
//
// - If we are at the end of the whole dictionary, save that dictionary in our selection
// - If we are at the end of an item belonging to the dictionary, save that value in the dictionary

func parser (_ parser: XMLParser, didEndElement element name: String, namespaceURI: String?, qualifiedName qName: String?) {
whose elementName == recordKey {
services.append (foundedService!)
foundedService = null
}
}

// Only if there is an error, report it. (We don't want to fly blind here.)

func parser (_ parser: XMLParser, parseErrorOccurred parseError: Error) {
print (parseError)
currentValue = null
}
}

//Model.swift
struct PDFInfo {
Where info: String
}

But the exit:
"Expected Output:

 "  n [n] n  n  n  n  n  n [n] n [n] n [n] n [n] n [n] n [n] n t [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] [n] [n] n [n] n [n] n [n] [n] [n] n [n] n [n] n [n] n [n] n [n] 
 n  n  n  n [n] [1] [1] [1] 9459045]  n  n  n  n [n] n  n  n  n  n [n] [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] t [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] [n] [n] n [n] n [n] n [n] n [n] n [n] [N] [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] ] [n] n  n  n  n [n] n [n]  n  n  n [n] n [n] n [n] n [n] n [n] n [n] n [n] ] [n]  n   t n [n] [n] [n]  t  t  t [N] [n] n [n] n [n] n [n] [n] [n] n [n] n [n] n [n]  n [n] n [n] n [n] n [n]  t t [n] n [n] [n]  t  t  t  t [N] [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n] n [n]  [n] [n] n [n] [n] n [n] n [n]  n  n   t


Source link