Skip to main content
bhaskarc1289447
Level 3
Jul 5, 2022 4:35 PM UTC
Question

parse xml passed inside <ctx> for Transactional template

Hi All,

 

i am getting the below xml inside my ctx of rt event

<ctx>

                <userMessage>

                    <userData>

                        <abc.alpha.new.system.User>

                            <userType>Fixed</userType>

                            <userBackground>Regular</ userBackground>

                            <productBookingDate>2015-05-8</productBookingDate >

 

when I am using --->  rtEvent.ctx.userMessage.userData.abc.alpha.new.system.User.userBackground ----- i am getting empty value
even if I use rtEvent.ctx.userMessage.userData.("abc.alpha.new.system.User").userBackground i still get empty value

 

Kindly suggest how to parse this xml to retrieve the value of 'userBackground' 

Please

 

@vraghav 

@_manoj_kumar_ 

@shrawansaxena-1 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

8 replies

CedricRey
Level 5
Jul 6, 2022 7:49 AM UTC

Hi @bhaskarc1289447 

Can you try this ? :

 

var doc = DOMDocument.fromXMLString(
    '<?xml version="1.0" encoding="ISO-8859-1"?>' +
    rtEvent.ctx.toXMLString());

var userBackground = doc.root.getElements('userMessage')[0]
                  .getElements('userData')[0]
                  .getElements('abc.alpha.new.system.User')[0]
                  .getElements('userBackground')[0].textContent;

Cedric

 

Translate
Sukrity_Wadhwa
Level 4
Jul 21, 2022 11:29 AM UTC

Hi @bhaskarc1289447,

Was the given solution helpful to resolve your query or do you still need more help here? Do let us know.

Thanks!

Translate
Sukrity Wadhwa
bhaskarc1289447
Level 3
Aug 23, 2022 8:27 AM UTC

Hi @sukrity_wadhwa 

 

we tried the solution but it did not work as 'DOMDocument' was not recognized inside transactional Template

Translate
Sukrity_Wadhwa
Level 4
Aug 24, 2022 6:36 AM UTC

Thanks for sharing this, @bhaskarc1289447. I will escalate it further among the Community experts.

 

Regards,

Sukrity

 

Translate
Sukrity Wadhwa
Adobe Employee
Aug 25, 2022 10:46 AM UTC

Hi @bhaskarc1289447 ,

 

The dot notation in the XML element causes the issue while parsing the XML.

 

Can you try this way by changing the payload: 

 

Instead of a dot use an underscore (abc_alpha_new_system_User) or CamelCase (abcAlphaNewSystemUser)

 

<ctx>

                <userMessage>

                    <userData>

                        <abc_alpha_new_system_User>

                            <userType>Fixed</userType>

                            <userBackground>Regular</ userBackground>

                            <productBookingDate>2015-05-8</productBookingDate >

 

And then try to access rtEvent.ctx.userMessage.userData.abc_alpha_new_system_User.userBackground.

 

Thanks,

Malarrajan Sundarraj.

Translate
Kishore_Padamata
Adobe Employee
Adobe Employee
Aug 26, 2022 3:13 PM UTC

Hello @bhaskarc1289447 
Please try 

ctx.userMessage.userData['abc.alpha.new.system.User'].userBackground

Hope this helps!

Translate
bhaskarc1289447
Level 3
Sep 23, 2022 8:13 AM UTC

Hi @kishore_padamata ,

 

Thank you for the reply. This solution also returns empty result.

Translate
Sukrity_Wadhwa
Level 4
Sep 22, 2022 7:18 AM UTC

Hi @bhaskarc1289447,

Were you able to resolve this query with the help of the given solutions or do you still need more help here? Do let us know. In case the given solutions were helpful, then kindly choose the one that helped you the most as the 'Correct Reply'.
Thanks!

Translate
Sukrity Wadhwa