UNPKG

@nx-dotnet/utils

Version:

This library was generated with [Nx](https://nx.dev).

35 lines 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readXmlInTree = readXmlInTree; exports.readXml = readXml; exports.iterateChildrenByPath = iterateChildrenByPath; const fs_1 = require("fs"); const xmldoc_1 = require("xmldoc"); function readXmlInTree(host, path) { const fileText = host.read(path)?.toString(); if (!fileText) { throw new Error(`Unable to read ${path}`); } return new xmldoc_1.XmlDocument(fileText); } function readXml(path) { const fileText = (0, fs_1.readFileSync)(path)?.toString(); if (!fileText) { throw new Error(`Unable to read ${path}`); } return new xmldoc_1.XmlDocument(fileText); } async function iterateChildrenByPath(root, path, callback) { const parts = path.split('.'); const children = root.childrenNamed(parts[0]); for (const childNode of children) { if (parts.length > 1) { const nextPath = parts.slice(1, parts.length).join('.'); await iterateChildrenByPath(childNode, nextPath, callback); } else { await callback(childNode); } } } //# sourceMappingURL=xml.js.map