martinh
February 10, 2010, 12:23pm
1
Hi,
I’m doing my first steps on the new webservice.
I’ve seen how you can do a reply.
var reply = new Object()
reply.elementname1 = value1
reply.elementname2 = value2
So far so good. But I want to give the following as a result:
<Reply>
<elementname1>value1</elementname1>
<elementname2>value2</elementname2>
<companies>
<company>
<id>123</id>
<name>company123</name>
</company>
<company>
<id>456</id>
<name>company456</name>
</company>
</companies>
</Reply>
So I thought:
var reply = new Object()
reply.elementname1 = value1
reply.elementname2 = value2
var companies = reply.companies = new Object()
var company = companies.company = new Object()
company.id=123
company.name=company123
var company = companies.company = new Object()
company.id=456
company.name=company456
This doesn’t work. Maybe doing something with array of objects?
But how to do this then?
Martin,
What about this:
var reply = new Object()
reply.Reply = new Object()
reply.Reply.elementname1 = value1
reply.Reply.elementname2 = value2
var company1 = new Object()
company1.id = 123
company1.name = 'company123'
var company2 = new Object()
company2.id = 456
company2.name = 'company456'
reply.Reply.companies = [company1, company2]
Rob
martinh
February 10, 2010, 3:07pm
3
Rob,
How do you get those company1, company2, …, companyx attached to that reply?
Or is there a way that I can use the XML-plugin of Drmaison and put final XML into an object so that it can be replied?
But that means that I need something like:
var reply = new Object()
reply.Reply = xmldocument.convertToObject()
and I don’t see such a method
Martin
martinh:
How do you get those company1, company2, …, companyx attached to that reply?
Did you try my sample above?
martinh:
Or is there a way that I can use the XML-plugin of Drmaison and put final XML into an object so that it can be replied?
No, the conversion from object to xml is done iside the plugin.
Rob
martinh
February 10, 2010, 5:52pm
5
rgansevles:
martinh:
How do you get those company1, company2, …, companyx attached to that reply?
Did you try my sample above?
Whatever I try, I don’t get the XML below:
<Reply>
<elementname1>value1</elementname1>
<elementname2>value2</elementname2>
<companies>
<company>
<id>123</id>
<name>company123</name>
</company>
<company>
<id>456</id>
<name>company456</name>
</company>
</companies>
</Reply>
The list with companies is unlimited.
Could it be an option to generate a long string and then make it an object using:
plugins.serialize.fromJSON(String)