SELECT
    CAST(event_data.value('(event/data/value)[1]', 'nvarchar(max)') AS XML) AS DeadlockGraphXml
FROM (
    SELECT CAST(target_data AS XML) AS TargetData
    FROM sys.dm_xe_sessions AS s
    JOIN sys.dm_xe_session_targets AS t
      ON s.address = t.event_session_address
    WHERE s.name = 'deadLocks'
      AND t.target_name = 'ring_buffer'
) AS SessionData
CROSS APPLY TargetData.nodes('//RingBufferTarget/event') AS EventNodes(event_data)
WHERE event_data.value('@name', 'nvarchar(100)') IN ('xml_deadlock_report', 'database_xml_deadlock_report');