NL.XML.Node.prototype.appendTo | Community
Skip to main content
Level 3
March 8, 2024
Solved

NL.XML.Node.prototype.appendTo

  • March 8, 2024
  • 1 reply
  • 461 views

 

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

 

 

 

"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>

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by isahore

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

 

1 reply

isahore
Community Advisor
isahoreCommunity AdvisorAccepted solution
Community Advisor
March 11, 2024

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