* Converts a body to XML format
(body: any)
| 430 | * Converts a body to XML format |
| 431 | */ |
| 432 | function convertBodyToXML(body: any): string { |
| 433 | // If body is already a string and looks like XML, return it as is |
| 434 | if (typeof body === 'string' && body.trim().startsWith('<')) { |
| 435 | return body; |
| 436 | } |
| 437 | |
| 438 | // If body is not an object, try to parse it as JSON |
| 439 | if (typeof body !== 'object' || body === null) { |
| 440 | try { |
| 441 | body = JSON.parse(body); |
| 442 | } catch { |
| 443 | // If parsing fails, return the original body |
| 444 | return body; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | return json2xml(body).replace(/"/g, '').replace(/\\n/g, '\n').replace(/\\t/g, '\t'); |
| 449 | } |
no test coverage detected