Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

NL.XML.Node.prototype.appendTo

Avatar

Level 3
Level 3

 

Using this ootb function, how do I append a new child to my xml ? story node

 

o_X_0-1709926388887.png

 

 

"use strict";

/**
 * @name NL.XML
 * @namespace
 */
loadLibrary("/nl/core/shared/nl.js");
loadLibrary("/nl/core/shared/xtk.js");

NL.ns('NL.XML');
NL.require('/nl/core/shared/nl.js').require('/nl/core/shared/xtk.js');
  /**
   * Append this to a specified node
   * @Param {NL.XML} element The element to append this to
   * @Returns {NL.XML} this
   */
  NL.XML.Node.prototype.appendTo = function (element) {
    NL.assert(element instanceof NL.XML.Node,'NL.XML.prototype.appendTo only accepts NL.XML instances as parameters');
    element.append(this);
    return this;
  };

 var myXml = <person>
              <cards>12345</cards>
              <points></points>
            </person>
            <story>
              <line>abc</line>
              <test>5</etst>
            </story>

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @o_X,

 

I have not used the appendTo method before, but what you are looking for can be done using the appendChild method, like this:

Let me know if that solves your purpose.

 

 

var newXml = <secondLine>new line</secondLine>;
myXml.story.appendChild(newXml);

 

BR,

Ishan

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @o_X,

 

I have not used the appendTo method before, but what you are looking for can be done using the appendChild method, like this:

Let me know if that solves your purpose.

 

 

var newXml = <secondLine>new line</secondLine>;
myXml.story.appendChild(newXml);

 

BR,

Ishan