0

I want to create XML file with array data like

"<?xml version='1.0' encoding='UTF-8'?><appname>Skype</appname><appname>Word</appname>"

var appname:[String]=["Skype","Word","Excell"]
let post = String(format: "<?xmlversion='1.0'encoding='UTF-8'?>\n\t<" appname=\"%@\" />\n</?xmlversion='1.0'encoding='UTF-8'?>", appname)

How to create XML? And how to send this XML to webservice?

0

2 Answers 2

0

Here's the code to build your Xml document

var appnames: [String] = [ "Skype", "Word", "Excell" ]
var post = "<?xmlversion='1.0'encoding='UTF-8'?><appnames>"

for appname in appnames
{
    let app_node: String = "<appname>\(appname)</appname>"
    post.append(app_node)
}

post.append("</appnames>")

Or if you prefer you can change for iterator with...

appnames.forEach({ post.append("<appname>\($0)</appname>") })

About sending this Xml document to a web service take a look at URLRequest Foundation class

Sign up to request clarification or add additional context in comments.

Comments

0
let appname=["Skype","Word","Excell"]
var post = "<?xml version='1.0' encoding='UTF-8'?>"
for stringItem in appname{
    post.append("<appname>\(stringItem)</appname>")
}
print(post)

1 Comment

it's the same code of the accepted answer. my answer and adolfo's answer was posted at the same time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.