2
<event sco-id="1302640315" type="event" icon="event" permission-id="view">
    <name>Salesforce Integration with External Systems</name>
    <domain-name>meet95927113.adobeconnect.com</domain-name>
    <url-path>/externalsystems/</url-path>
    <date-begin>2017-12-15T01:30:00.000+14:00</date-begin>
    <date-end>2017-12-15T02:30:00.000+14:00</date-end>
    <expired>true</expired>
    <duration>01:00:00.000</duration>
</event>

I'm parsing the above xml data like below:

if(node.getName()=='name')
    adobeevent.name=node.getText().trim();
if(node.getName()=='_sco-id')
    adobeevent.LightiningEd__SCO_ID__c=node.getText().trim();
if(node.getName()=='domain-name')
    adobeevent.LightiningEd__Registration_URL__c= node.getText().trim();
if(node.getName()=='date-begin')
    adobeevent.LightiningEd__Start_Time__c = date.valueOf(node.getText().trim());
if(node.getName()=='date-end')
    adobeevent.LightiningEd__Finish_Time__c =  date.valueOf(node.getText().trim());
if(node.getName()=='expired')
    adobeevent.LightiningEd__Expired__c=node.getText().trim();

But how to to parse the below user data like name,login,attandance_status?

<user_list>
    <user principal_id="1300650026" permission_id="View" name="chanbasha sk" login="[email protected]" registration_time=" " attendance_status="Attended" first_in_time=" " duration="01:21:49" isLead="No" registration_question_1302377328=" " campaign_alias_1302377328=" " registration_question_-400002=" " campaign_alias_-400002=" " registration_question_-400007=" " campaign_alias_-400007=" " registration_question_-400009=" " campaign_alias_-400009=" " registration_question_-4000012=" " campaign_alias_-4000012=" " registration_question_-4000015=" " campaign_alias_-4000015=" " registration_question_1303602670=" " campaign_alias_1303602670=" " idp-source=" "/>
    <user principal_id="1302405871" permission_id="View" name="Nawaaz Sk" login="[email protected]" registration_time="12/14/2017 7:33 AM" attendance_status="Attended" first_in_time=" " duration="00:00:07" isLead="Yes" registration_question_1302377328=" " campaign_alias_1302377328=" " registration_question_-400002="Miracle" campaign_alias_-400002=" " registration_question_-400007="Andhra Pradesh" campaign_alias_-400007=" " registration_question_-400009="India" campaign_alias_-400009=" " registration_question_-4000012="8466015478" campaign_alias_-4000012=" " registration_question_-4000015="5000" campaign_alias_-4000015=" " registration_question_1303602670=" " campaign_alias_1303602670=" " idp-source=" "/>
    <user principal_id="1302429015" permission_id="View" name="Chan Sk" login="[email protected]" registration_time="12/14/2017 7:38 AM" attendance_status="Attended" first_in_time=" " duration="00:01:22" isLead="Yes" registration_question_1302377328=" " campaign_alias_1302377328=" " registration_question_-400002="Miracle" campaign_alias_-400002=" " registration_question_-400007="Andhra Pradesh" campaign_alias_-400007=" " registration_question_-400009="India" campaign_alias_-400009=" " registration_question_-4000012="8466015478" campaign_alias_-4000012=" " registration_question_-4000015="4000" campaign_alias_-4000015=" " registration_question_1303602670=" " campaign_alias_1303602670=" " idp-source=" "/>
</user_list>
1
  • @glls I think the LMGTFY link is a little bit harsh given that the question is really 'how do I retrieve the value of an attribute from a node in the xml'.
    – Mark Pond
    Dec 21, 2017 at 18:09

1 Answer 1

2

You do this by using the XmlNode.getAttributeValue() method.

string s = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><user_list><user principal_id="1300650026" permission_id="View" name="chanbasha sk" login="[email protected]" registration_time=" " attendance_status="Attended" first_in_time=" " duration="01:21:49" isLead="No" registration_question_1302377328=" " campaign_alias_1302377328=" " registration_question_-400002=" " campaign_alias_-400002=" " registration_question_-400007=" " campaign_alias_-400007=" " registration_question_-400009=" " campaign_alias_-400009=" " registration_question_-4000012=" " campaign_alias_-4000012=" " registration_question_-4000015=" " campaign_alias_-4000015=" " registration_question_1303602670=" " campaign_alias_1303602670=" " idp-source=" "/><user principal_id="1302405871" permission_id="View" name="Nawaaz Sk" login="[email protected]" registration_time="12/14/2017 7:33 AM" attendance_status="Attended" first_in_time=" " duration="00:00:07" isLead="Yes" registration_question_1302377328=" " campaign_alias_1302377328=" " registration_question_-400002="Miracle" campaign_alias_-400002=" " registration_question_-400007="Andhra Pradesh" campaign_alias_-400007=" " registration_question_-400009="India" campaign_alias_-400009=" " registration_question_-4000012="8466015478" campaign_alias_-4000012=" " registration_question_-4000015="5000" campaign_alias_-4000015=" " registration_question_1303602670=" " campaign_alias_1303602670=" " idp-source=" "/><user principal_id="1302429015" permission_id="View" name="Chan Sk" login="[email protected]" registration_time="12/14/2017 7:38 AM" attendance_status="Attended" first_in_time=" " duration="00:01:22" isLead="Yes" registration_question_1302377328=" " campaign_alias_1302377328=" " registration_question_-400002="Miracle" campaign_alias_-400002=" " registration_question_-400007="Andhra Pradesh" campaign_alias_-400007=" " registration_question_-400009="India" campaign_alias_-400009=" " registration_question_-4000012="8466015478" campaign_alias_-4000012=" " registration_question_-4000015="4000" campaign_alias_-4000015=" " registration_question_1303602670=" " campaign_alias_1303602670=" " idp-source=" "/></user_list>';

Dom.Document d = new Dom.Document();
d.load(s);
Dom.XmlNode userList = d.getRootElement();

for (Dom.XmlNode userNode : userList.getChildElements()) {
    system.debug(userNode.getAttributeValue('principal_id', null) + ' : ' + userNode.getAttributeValue('name', null) + ' : ' + userNode.getAttributeValue('attendance_status', null));
}

Results

USER_DEBUG|[8]|DEBUG|1300650026 : chanbasha sk : Attended
USER_DEBUG|[8]|DEBUG|1302405871 : Nawaaz Sk : Attended
USER_DEBUG|[8]|DEBUG|1302429015 : Chan Sk : Attended

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .