I need to parse this xml and get last-name by Id(99999) or by Id(55555) based on what I set in the method.
<?xml version="1.0"?>
<xmldata
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" status="SUCCESS">
<recordset name="object" nritems="1" acl="AW">
<record name="object" id="99999" acl="DW">
<field name="last-name" acl="TW">**SS**</field>
</record>
<record name="object" id="55555" acl="DW">
<field name="last-name" acl="TW">**Jony**</field>
</record>
</recordset>
</xmldata>
I am trying this but get only firsr value
DOM.Document document = new DOM.Document();
document.load(responseBody);
String subjectID = document.getRootElement()
.getChildElement('recordset', null)
.getChildElement('record', null).getAttribute('id', '');
String name;
for (Dom.XmlNode xmlNode : document.getRootElement()
.getChildElement('recordset', null)
.getChildElement('record', null).getChildElements()) {
if (xmlNode.getAttribute('name', '') == 'name') {
name = xmlNode.getText();
}
}
System.debug(
subjectID
);
System.debug(name);