function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaurav Jain 67Gaurav Jain 67 

How to Parse a XML which is present as a small section in a JSON format API response

I  need to parse a value 'TotalMatchScore' from  the small XML sectionof the below JSON code:

{
  "Header": {
    "Source": "SFDC",
    "UniqueId": "XXXXXX",
    "Target": "ServiceName",
    "DateTime": "2018-10-26 11:33:13"
  },
  "Detail": {
    "ApplicationID": "xxx",
    "BureauStatus": "Success",
    "BureauError": {
      "ErrorCode": null,
      "ErrorMessage": null
    },
    "BureauResponse": [
      {
        "ApplicantID": null,
        "ProcessedRequest": [
          {
            "@nil": "",
            "BureauId": 11,
            "BureauProduct": {
              "@nil": "true",
              "BureauId": null,
              "CategoryAlias": null,
              "IsALL": null,
              "IsActive": null,
              "IsEnquiryCreated": null,
              "LOSId": null,
              "Priority": null,
              "ProductCode": {
                "@nil": ""
              },
              "ProductId": null,
              "ProductName": {
                "@nil": ""
              },
              "RefNo": null,
              "RuleIdList": {
                "@nil": ""
              }
            },
            "ConsumerName": {
              "@nil": "true"
            },
            "Error": {
              "@nil": "true"
            },
            "ErrorCode": {
              "@nil": "true"
            },
            "ErrorDetail": {
              "@nil": "true"
            },
            "ExistingRefNo": 0,
            "LOSApplicationNo": {
              "@nil": "",
              "$": "XXXXXX"
            },
            "ProcessingTime": {
              "@nil": "",
              "$": "00:00:01.9591036"
            },
            "ReferenceNumber": 94717,
            "ResponseType": "Normal",
            "ResponseXML": {
              "@nil": "",
              "$": "<ResultBlock><MatchSummary matches=\"0\"><TotalMatchScore /></MatchSummary><ErrorWarnings><Errors errorCount=\"0\" /><Warnings warningCount=\"1\"><Warning><Number>102009</Number><Message>Match schemes not used</Message><Values><Value>317</Value><Value>318</Value><Value>676</Value><Value>64</Value><Value>138</Value><Value>141</Value><Value>142</Value><Value>145</Value></Values></Warning></Warnings></ErrorWarnings></ResultBlock>"
            },
            "Status": {
              "@nil": "",
              "$": "Finished"
            },
            "TimeOutStatus": {
              "@nil": "",
              "$": "NoHit"
            },
            "XMLFileName": {
              "@nil": "true"
            }
          }
        ]
      }
    ],
    "BreStatus": "Error",
    "BreError": {
      "ErrorCode": "TW-001",
      "ErrorMessage": "Evaluation error \nExpression produces unexpected value: Invalid index: 0.\nInvalid index: 0 while evaluating function fn_Definitions "
    },
    "BREResponse": [
      {
        "response": {
          "systemDecision": null,
          "systemDecisionDateTime": null,
          "strategyUsed": null,
          "finalApprovalLevel": null,
          "policyRulesDecision": null,
          "scoreDecision": null
        },
        "Invocation": {
          "version": null,
          "applicationNumber": null,
          "transactionId": null,
          "applicationDate": null,
          "decisionPoint": null,
          "decisionService": null,
          "responseStatus": null,
          "error": {
            "stackTrace": null,
            "source": null,
            "dateTime": null,
            "errorCode": null,
            "description": null
          }
        }
      }
    ]
  },
  "STATUS": "SUCCESS"
}

Please help !
Regards,
Gaurav
Adilson Arcoverde JrAdilson Arcoverde Jr
Hi,

Following your XML input file example, I would use this code:
 
String xmlContent = '...<TotalMatchScore>10</TotalMatchScore>...';
String totalMatchScore = xmlContent.substringBetween('<TotalMatchScore>','</TotalMatchScore>');
System.debug( totalMatchScore ); // you'll get 10 as result

Does this make any sense?

Regards.