cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing XML response of an external web service in webscript

a_kholodkov
Champ in-the-making
Champ in-the-making
Hello,

I`ve been unsuccesfully trying to do a really general thing in Alfresco two days already    :x  - to parse XML-response of an external web service and show it in Share.
I have made a custom page in Share to show result, set up endpoint for the web service, written a web script etc. Everything works fine.

But I cannot parse XML-output of the WS. I can show fully XML-output without parsing, but I want to use only part of the data. So I want to parse it.

I do the next (this is simplified variant).

1). In *.js

var xmlRespTest = "<book><page>1</page><page>2</page><page>3</page></book>";
model.data = xmlRespTest;

2). In *ftl

<#assign dom = data.xmlNodeModel>

Then I have error message:
freemarker.template.TemplateException - Expected hash. data evaluated instead to freemarker.template.SimpleScalar

Can anybody help me? What do I do wrong?

Thanks in advance!
11 REPLIES 11

Hi,

Thanks a lot! It works!
After all I realized my script wasn't working because my log test (somehow it didn't work out with this)



var fileContent = document.content;
var xml = new XML(fileContent);
var cUF = xml.NFe.infNFe.ide.cUF;

//LOG TEST (wrong)

var logFile = space.childByNamePath("log.txt");
if (logFile == null)
{
   logFile = space.createFile("log.txt");
}
logFile.content = "";
logFile.content = cUF; // it returns a blank log
logFile.save();


Thanks a lot!

kaynezhang
World-Class Innovator
World-Class Innovator
Good luck.
And a little advice,next time when you paste your code ,you can wrap it within  <code> </code ,it is easy for others to read.