( node: XmlDocument | XmlElement, options?: StringifyOptions, )
| 41 | * @returns The serialized XML string. |
| 42 | */ |
| 43 | export function stringify( |
| 44 | node: XmlDocument | XmlElement, |
| 45 | options?: StringifyOptions, |
| 46 | ): string { |
| 47 | const { indent, declaration = true } = options ?? {}; |
| 48 | |
| 49 | // Check if it's a document (has 'root' property) or an element |
| 50 | if ("root" in node) { |
| 51 | let result = ""; |
| 52 | if (declaration && node.declaration) { |
| 53 | result += serializeDeclaration(node.declaration); |
| 54 | if (indent !== undefined) { |
| 55 | result += "\n"; |
| 56 | } |
| 57 | } |
| 58 | result += serializeElement(node.root, indent, 0); |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | // It's an element |
| 63 | return serializeElement(node, indent, 0); |
| 64 | } |
| 65 | |
| 66 | /** Serializes an XML declaration to a string. */ |
| 67 | function serializeDeclaration(decl: XmlDeclaration): string { |
no test coverage detected