@rxap/xml-parser
Version:
Provides a set of decorators and services for parsing and serializing XML documents into TypeScript classes. It simplifies the process of mapping XML elements and attributes to class properties, handling data validation, and serializing objects back into
48 lines • 2.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseDefinitionElement = void 0;
exports.ParseBaseDefinitionElement = ParseBaseDefinitionElement;
const tslib_1 = require("tslib");
const element_attribute_1 = require("../decorators/element-attribute");
class BaseDefinitionElement {
constructor(id) {
this.metadata = {};
if (id) {
this.id = id;
}
}
getMetaData() {
return Object.assign(Object.assign({}, this.metadata), { id: this.id });
}
}
exports.BaseDefinitionElement = BaseDefinitionElement;
tslib_1.__decorate([
(0, element_attribute_1.ElementAttribute)(),
tslib_1.__metadata("design:type", String)
], BaseDefinitionElement.prototype, "id", void 0);
/**
* Parses an XML element to update and populate properties of a BaseDefinitionElement object.
*
* This function takes an XML element and extracts relevant data to populate or update the properties
* of a given BaseDefinitionElement object. It specifically updates the 'id' and 'metadata' properties
* of the BaseDefinitionElement. If the XML element contains an 'id' attribute, it updates the 'id' of
* the BaseDefinitionElement. It also checks for a 'metadata' child node within the XML element, and if
* present, iterates over its child nodes to populate the 'metadata' dictionary of the BaseDefinitionElement
* with key-value pairs, where the key is the node name and the value is the text content of the node.
*
* @param {XmlParserService} parser - The XML parser service used to parse the XML document.
* @param {RxapElement} element - The XML element that contains data to be parsed and used for updating the BaseDefinitionElement.
* @param {BaseDefinitionElement} baseDefinitionElement - The BaseDefinitionElement object to be updated with data from the XML element.
* @returns {BaseDefinitionElement} The updated BaseDefinitionElement object.
*/
function ParseBaseDefinitionElement(parser, element, baseDefinitionElement) {
baseDefinitionElement.id = element.getString('id', baseDefinitionElement.id);
if (element.hasChild('metadata')) {
const metadataElement = element.getChild('metadata');
for (const child of metadataElement.getAllChildNodes()) {
baseDefinitionElement.metadata[child.name] = child.getTextContent();
}
}
return baseDefinitionElement;
}
//# sourceMappingURL=definition.element.js.map