MCPcopy
hub / github.com/GitbookIO/gitbook / convertBodyToXML

Function convertBodyToXML

packages/react-openapi/src/code-samples.ts:432–449  ·  view source on GitHub ↗

* Converts a body to XML format

(body: any)

Source from the content-addressed store, hash-verified

430 * Converts a body to XML format
431 */
432function 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}

Callers 2

getCurlBodyFunction · 0.85
code-samples.tsFile · 0.85

Calls 2

json2xmlFunction · 0.90
parseMethod · 0.65

Tested by

no test coverage detected