Skip to content

Commit

Permalink
fix(DASH): Fix EventStream Elements creation (#7194)
Browse files Browse the repository at this point in the history
Related to #7148 
Does not create parent elements anymore to reduce memory consumption.
Starts to use `createElementNS()` so created elements will keep proper
cases for tag names and they won't be anymore of type `HTMLElement`, but
`Element`, which should be more lightweight and suitable for our needs.
  • Loading branch information
tykus160 authored and avelad committed Aug 26, 2024
1 parent 29a7e8d commit 51f4c3f
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions lib/util/tXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,36 +869,25 @@ shaka.util.TXml = class {
/**
* Converts a tXml node to DOM element.
* @param {shaka.extern.xml.Node} node
* @param {boolean=} doParents
* @param {boolean=} doChildren
* @return {!Element}
*/
static txmlNodeToDomElement(node, doParents = true, doChildren = true) {
static txmlNodeToDomElement(node) {
const TXml = shaka.util.TXml;
const element = document.createElement(node.tagName);
const element = document.createElementNS('', node.tagName);

for (const k in node.attributes) {
const v = node.attributes[k];
element.setAttribute(k, v);
}

if (doParents && node.parent && node.parent.tagName != '?xml') {
const parentElement = TXml.txmlNodeToDomElement(
node.parent, /* doParents= */ true, /* doChildren= */ false);
parentElement.appendChild(element);
}

if (doChildren) {
for (const child of node.children) {
let childElement;
if (typeof child == 'string') {
childElement = new Text(child);
} else {
childElement = TXml.txmlNodeToDomElement(
child, /* doParents= */ false, /* doChildren= */ true);
}
element.appendChild(childElement);
for (const child of node.children) {
let childElement;
if (typeof child == 'string') {
childElement = new Text(child);
} else {
childElement = TXml.txmlNodeToDomElement(child);
}
element.appendChild(childElement);
}

return element;
Expand Down

0 comments on commit 51f4c3f

Please sign in to comment.