Forum Discussion

dhiraj_gophane's avatar
11 years ago

How to catch and parse XML response generated from community event subscription notification?

Hi all,

We are using endpoint url as a call-back url for messageCreate event.

So whenever a message is created in community we get a response.

 

I think the response is in three parameters:

1. token

2.event.type

3.message (in XML format)

 

I want to fetch message_id from the xml.

 

I am using following snippet:

<#assign msgToken = http.request.parameters.name.get("token","") />
<#assign msgEvent = http.request.parameters.name.get("event.type","") />
<#assign msgNode = http.request.parameters.name.get("message","") />

 

I'm able to get 1st two parameters but I am facing issues while reading 3rd parameter. (i.e. message)

I'm refering following article for this POC:
http://lithosphere.lithium.com/t5/developers-knowledge-base/Subscribing-to-community-events-using-the-REST-API/ta-p/14785

 

How can I do this in freemarker?

Kindly help.

  • Hey Dhiraj,

     

    Unfortunately, we do not currently have a mechanism by which to convert an XML string to an object. I would suggest adding a suggestion on our Customer Ideas page. This leaves you with a few options.

     

    1) Use substring to get the information you want (not a great approach, but will work)

     

    <#assign msgNode = http.request.parameters.name.get("message","")/>
    
    <#if msgNode?length != 0>
      <#assign startString = '<id type="int">'>
      <#assign endString = '</id>'>
      <#assign startIndex = msgNode?index_of(startString)+startString?length>
      <#assign endIndex = msgNode?index_of(endString)>
    
      <#if startIndex != startString?length-1>
        <#if endIndex != -1>
    
          ${msgNode?substring(startIndex,endIndex)}
        </#if>
      </#if>
    </#if>

     2) Use javascript to convert the XML string to an object (it will then only be usable in javascript) (I haven't tried this yet, but it should work)

     

    There maybe other approaches that would work, but these were the 2 that popped to my mind.

     

    Hope this helps,

     

    Yuri

2 Replies

  • YuriK's avatar
    YuriK
    Khoros Expert
    11 years ago

    Hey Dhiraj,

     

    Unfortunately, we do not currently have a mechanism by which to convert an XML string to an object. I would suggest adding a suggestion on our Customer Ideas page. This leaves you with a few options.

     

    1) Use substring to get the information you want (not a great approach, but will work)

     

    <#assign msgNode = http.request.parameters.name.get("message","")/>
    
    <#if msgNode?length != 0>
      <#assign startString = '<id type="int">'>
      <#assign endString = '</id>'>
      <#assign startIndex = msgNode?index_of(startString)+startString?length>
      <#assign endIndex = msgNode?index_of(endString)>
    
      <#if startIndex != startString?length-1>
        <#if endIndex != -1>
    
          ${msgNode?substring(startIndex,endIndex)}
        </#if>
      </#if>
    </#if>

     2) Use javascript to convert the XML string to an object (it will then only be usable in javascript) (I haven't tried this yet, but it should work)

     

    There maybe other approaches that would work, but these were the 2 that popped to my mind.

     

    Hope this helps,

     

    Yuri