Converting using XBEE from Arduino to ESP32

I have been using the following line to use XBEE with arduino:
SoftwareSerial xbee = SoftwareSerial(RX_PIN, TX_PIN);

But SoftwareSerial doesn't work for ESP32.
How can I use XBEE with ESP32?

You didn't say which esp32 you have, but most (all?) have more than 1 serial port. Use a second hardware serial port.

you would use a hardware serial port if there is one free

you could do just

HardwareSerial xbee(2); // aka Serial2

void setup() { 
  // Initialize Serial2 with desired baud rate and pins
  mySerial.begin(9600, SERIAL_8N1, 16, 17); // RX = GPIO16, TX = GPIO17

...
}