You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can pretty much do whatever you like in the mapping process by implementing your own custom XMLTransformType.
To map the first word of the food element's value, your can use:
classFirstWordTransform:XMLTransformType{typealiasObject=StringtypealiasXML=Stringfunc transformFromXML(_ value:Any?)->Object?{
if let stringValue = value as?String{return stringValue.components(separatedBy:"").first
}returnnil}func transformToXML(_ value:Object?)->XML?{// If you don't want το discard the rest of the string value in the serialization process,// you can probably keep it in a variable inside this XMLTransformType's instance AND// keep this XMLTransformType's instance inside Reponse class instance.// (although this will not be so pretty)return value
}}classResponse:XMLMappable{varnodeName:String!varfoodFirstWord:String?requiredinit(map:XMLMap){}func mapping(map:XMLMap){
foodFirstWord <-(map["food"],FirstWordTransform())}}
Hi @gcharita,
Is that possible to parse just the first word or the portion I want from the xml?
ex:
In this case I need just the first word, "Belgian" from food.
<Response> <food>Belgian Waffles</food> </Response>
The text was updated successfully, but these errors were encountered: