0 votes
in SoSci Survey (English) by s057462 (330 points)

Hi Dominik
we would like to use responses retained in the first half of the survey (160 trials) to send the in a specific format to a server which makes some calculations and sends the result back to soscisurvey, and use that response to create subsequent questions (specify some amounts shown there).
In the past we have done a simpler version where we only sent s string of numbers to the server, but now we need to send all trial's responses and the definition of which type of trial they came from, so we would need to put that into a format that contains all that information and thought we'd use xml.
Is there a way to create a xml file from the obtained responses which can be sent to a server? The API section mentions JSON and csv only and I saw in another post that $curl = curl_init($url) is not usable, but maybe you have an idea how we could do this in another way?
Thanks you very much for your help.
All the best

1 Answer

0 votes
by SoSci Survey (312k points)

so we would need to put that into a format that contains all that information and thought we'd use xml.

JSON would probably be more convenient ... just a thought.

How did you do the sending so far?

curl_init($url) is not usable

No, but there will be some replacement in SoSci Survey soon. This is why I am asking for details - in order to make the function most useful for you :)

Is there a way to create a xml file from the obtained responses which can be sent to a server?

If you created an array with all question IDs that you'd like to send, that's white easy to accomplish by using a FOR loop and valueList(). But, as stated above, JSON might be much easier to encode AND to decode.

by SoSci Survey (312k points)
The response is XML, or at least parsed as XML (HTML may be XML as well). Therefore sendXML() will try and parse it, and return an array.

Please try this to see more details:

debug($answer)
by s057462 (330 points)
Thanks, the debug function shows that:
Debug information for $answer:
namehtml, attr[Array], value , children[Array]


Also: it seems like the information we are sending is a string (rather than an xml) as what gets there is:
<data attr="S102_03">1</data>

Here is my code as it stands:

// create xml
$xml = '<?xml version="1.0" encoding="UTF-8"?'.'>';

//Then continue with some root tag:
$xml= '<myData>';

//And then add XML with your data:
//set the ID in $xmlPacket, called once
$xml = '<data attr="ID">'.htmlspecialchars(caseNumber()).'</data>';

// write the responses
for ($n = 0; $n < 3; $n++) {
    $xml = '<data attr="'.id('S101', $n+1).'">'.htmlspecialchars(value(id('S101', $n+1))).'</data>';
};

for ($n = 0; $n < 3; $n++) {
    $xml = '<data attr="'.id('S102', $n+1).'">'.htmlspecialchars(value(id('S102', $n+1))).'</data>';  
};


// send xml
$answer = sendXML('http://dd.virtualpsyclab.net/ddgem/ddgem', $xml);

debug($answer);


Do you know what need to be changed to get sent as the actual xml?
Thank you!
by SoSci Survey (312k points)
> Do you know what need to be changed to get sent as the actual xml?

The actual XML is sent, but it seems that the counterpart already strips away the root tag <myData> surrounding the data.

> Thanks, the debug function shows that

Looks reasonable. The <html> tag is the root tag of an HTML document. That means that the array $answer['children'] should contain two elements. One for the <head> and one for the <body> tag. And the <body> then probably contains the contents you are looking for.
by s057462 (330 points)
Okay, I edited what is sent so it actually adds all columns using this:
// create xml
$xml = '<?xml version="1.0" encoding="UTF-8"?'.'>';

//Then continue with root tag:
$xml+= '<myData>';

//And then add data to XML:
//set the ID in $xmlPacket, called once
$xml += '<data attr="ID">'.htmlspecialchars(caseNumber()).'</data>';

// write the responses
for ($n = 0; $n < 3; $n++) {
    $xml += '<data attr="'.id('S101', $n+1).'">'.htmlspecialchars(value(id('S101', $n+1))).'</data>';
};

for ($n = 0; $n < 3; $n++) {
    $xml += '<data attr="'.id('S102', $n+1).'">'.htmlspecialchars(value(id('S102', $n+1))).'</data>';  
};

//closing tag
$xml+= '</myData>';
 
 
// send xml
$answer = sendXML('http://dd.virtualpsyclab.net/ddgem/ddgem', $xml);

debug($answer);


But I get the error:
The contents specified in sendXML() is no valid XML.

and
Debug information for $answer:
$answer = false (boolean)
by SoSci Survey (312k points)
Please note that PHP does not use a plus (+) to concatenate strings, but the dot (.), i.e.

$xml.= '<myData>';

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...