Не удалось удалить или заменить &
на &
из строки синтаксического анализа xml. Я перепробовал все возможности, и я не знаю, где что-то идет не так, или как удалить или заменить это на &.
let changeStr = getLocation.replacingOccurrences(of: "&", with: "&")
этот вызов не заменяет.
// XML Get Loaction
let LocationMessage = "<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns1='http://tempuri.org/'><SOAP-ENV:Body><ns1:GetBROMCoordinateByLatLogRad><ns1:latitude>\(place.coordinate.latitude)</ns1:latitude><ns1:logitude>\(place.coordinate.longitude)</ns1:logitude><ns1:radius>500</ns1:radius></ns1:GetBROMCoordinateByLatLogRad></SOAP-ENV:Body></SOAP-ENV:Envelope>"
let LocationurlString = "http://xyz/POSCustAppWebService/API/POSApiService.svc"
let LocationmsgLength = String(LocationMessage.count)
let LocationUrl = NSURL(string: LocationurlString)!
var LocationRequest = URLRequest(url: LocationUrl as URL)
LocationRequest.addValue("text/xml", forHTTPHeaderField: "Content-Type")
LocationRequest.addValue("http://tempuri.org/IPOSApiService/GetBROMCoordinateByLatLogRad", forHTTPHeaderField: "Soapaction")
LocationRequest.addValue(LocationmsgLength, forHTTPHeaderField: "Content-Length")
LocationRequest.httpMethod = "POST"
LocationRequest.httpBody = LocationMessage.data(using: .utf8)
let Locationsession = URLSession.shared
let Locationtask = Locationsession.dataTask(with: LocationRequest as URLRequest) { (data, response, error) in
guard let Locationresponse = data,
error == nil else {
print(error?.localizedDescription ?? "Response Error")
return }
print("Track Response: \(String(describing: response))")
let Locationparser = XMLParser(data: Locationresponse)
Locationparser.delegate = self
Locationparser.parse()
}
Locationtask.resume()
// MARK: - методы делегата XML
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {
currentParsingElement = elementName
if elementName == "GetBROMCoordinateByLatLogRadResponse" {
print("Started parsing...")
}
}
func parser(_ parser: XMLParser, foundCharacters string: String) {
let foundedChar = string.trimmingCharacters(in:NSCharacterSet.whitespacesAndNewlines)
if (!foundedChar.isEmpty) {
if currentParsingElement == "GetBROMCoordinateByLatLogRadResult" {
getLocation = foundedChar
print("Location is",getLocation)
// let encodedHost = unencodedHost.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
/* let encoded = "<strong> 4 < 5 & 3 > 2 .</strong> Price: 12 €. @ "
let decoded = encoded.stringByDecodingHTMLEntities
print(decoded)
// <strong> 4 < 5 & 3 > 2 .</strong> Price: 12 €. @
*/
let jsonData = getLocation.data(using: .utf8)
do{
let jsonResponse = try JSONSerialization.jsonObject(with: jsonData!, options: .allowFragments)
print("JSON Data is", jsonResponse) //Response result
guard let jsonArray = jsonResponse as? [[String: Any]]
else {
return
}
print("JSON Array is", jsonArray)
for outletFinderresult in jsonArray {
let outletFinderData = outletFinder()
outletFinderData.BranchName = outletFinderresult["BranchName"] as! String
print("Branch Name", outletFinderData.BranchName)
outletFinderData.BranchType = outletFinderresult["BranchType"] as! String
print("Branch Type", outletFinderData.BranchType)
outletFinderData.BranchContactNo = outletFinderresult["BranchContactNo"] as! String
print("Branch ContactNo", outletFinderData.BranchContactNo)
let getOperatioHours = outletFinderresult["OperationHours"] as! String
let removeN = String(getOperatioHours.filter { !"\n".contains($0) })
outletFinderData.OperationHours = removeN
print("Operation Hours", outletFinderData.OperationHours)
var postString = outletFinderresult["BranchAddress1"] as! String
postString += [","]
postString += outletFinderresult["BranchAddress2"] as! String
postString += [","]
postString += outletFinderresult["BranchAddress3"] as! String
postString += [","]
postString += outletFinderresult["Postcode"] as! String
postString += [","]
postString += outletFinderresult["City"] as! String
postString += [","]
outletFinderData.Address = postString
print("Address", outletFinderData.Address)
outletFinderData.Latitude = (outletFinderresult["Latitude"] as! NSString).doubleValue
print("Latitude", outletFinderData.Latitude)
outletFinderData.Longitude = (outletFinderresult["Longitude"] as! NSString).doubleValue
print("Longitude", outletFinderData.Longitude)
self.trackOutletFinder.append(outletFinderData)
}
DispatchQueue.main.async {
self.outletCollectionView.reloadData()
// elf.outletCollectionView.collectionViewLayout.invalidateLayout()
}
} catch let parsingError {
print("Error", parsingError)
}
}
}
}
func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
if elementName == "GetBROMCoordinateByLatLogRadResponse" {
print("Ended parsing...")
}
}