我已经使用xml映射输出了一个xml文件。现在,我需要使用宏在特定标签和文本周围添加CDATA。
任何帮助将不胜感激。
我现有的xml文件。
func displayAlerts(setCompletion: @escaping (Bool) -> ()) {
print(" MapArray.alertNotificationCoordinatesArray before displayAlert snapshot is: \(MapArray.alertNotificationCoordinatesArray)")
print(" self.userAlertNotificationArray before displayAlert snapshot is: \(self.userAlertNotificationArray)")
if self.userAlertNotificationArray.count == 0 {
ref = Database.database().reference()
ref?.child("Continent").child("Europe").child("Country").child("Italy").child("Region").child("Emilia-Romagna").child("City").child("Bologna").child("Community").child("Alert Notifications").observeSingleEvent(of: .value, with: { (snapshot) in
print(" snapshot is: \(snapshot)")
guard let data = snapshot.value as? [String :[String:String]] else { return } // checking if the snapshot is the dictonary in the form of [String :[String:String]] else return
for snap in snapshot.children {
let alertSnap = snap as! DataSnapshot // casting the snapshot children is the dictonary in the form of [String:String]
let childrenKey = alertSnap.key
let alert = alertSnap.value as! [String:String]
let dataLatitude = alert["Latitude"]!
let dataLongitude = alert["Longitude"]!
let type = alert["Description"]!
let id = Int(alert["Id"]!)!
print("Node Key is: \(snapshot.key)")
print("childrenKey is:\(childrenKey)")
print("dataLatitude is: \(String(describing: dataLatitude))")
print("dataLongitude is: \(String(describing: dataLongitude))")
print("type is: \(String(describing: type))")
print("id is: \(String(describing: id))")
print("data is: \(data)")
let doubledLatitude = Double(dataLatitude)
let doubledLongitude = Double(dataLongitude)
let recombinedCoordinate = CLLocationCoordinate2D(latitude: doubledLatitude!, longitude: doubledLongitude!)
let userAlertAnnotation = UserAlert(type: type, coordinate: recombinedCoordinate, firebaseKey: childrenKey, title: type,id: id)
self.userAlertNotificationArray.append(userAlertAnnotation) // array of notifications coming from Firebase
MapArray.alertNotificationCoordinatesArray.append(recombinedCoordinate)
}
print("Firebase alerts posts retrieved")
print(" MapArray.alertNotificationCoordinatesArray after displayAlert snapshot is: \(MapArray.alertNotificationCoordinatesArray)")
print(" self.userAlertNotificationArray after displayAlert snapshot is: \(self.userAlertNotificationArray)")
self.mapView.addAnnotations(self.userAlertNotificationArray)
setCompletion(true)
})
}
}
我要添加CDATA,它必须如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<QML>
<QUESTION DESCRIPTION="Eliminate means:" TOPIC="1\2\A" STATUS="Normal">
<CONTENT TYPE="text/html">
<STEM><P><STRONG>Eliminate means:<BR></STRONG></P></STEM>
<IMG src="SRC" border="1"/>
</CONTENT>
<ANSWER QTYPE="MC" SHUFFLE="YES" SUBTYPE="VERT">
<CHOICE ID="0">remove</CHOICE>
<CHOICE ID="1">assemble</CHOICE>
<CHOICE ID="2">maintain</CHOICE>
<CHOICE ID="3">fractionate</CHOICE>
</ANSWER>
</QUESTION>
<QML>