javascriptnode.jsxmlsaxxml-builder

How to add a custom tag in xml using xmlbuilder package in node javascript


I am having a case where I want to add this tag in my xml just below the prolog something like this :

<?xml version="1.0"?>
<?AXOXMLMAP FILE=gnvouchr LIBRARY=. ;VOLUME=xmlmap?>

I am able to add the first line , but not getting how do I add the second line. If I use create it adds the closing tag as well. I just want this one single tag with the properties I have mentioned.

I am using xmlbuilder npm package. If there is any other npm package that can serve this purpose, that would work too.


Solution

  • WIth some research I found out that the line after prolog which I have mentioned below is preprocessing information ( instructions ). To add instructions we can either use : instructionBefore/instructionAfter or instruction for adding pre-processing information using xmlbuilder npm package.

    Eg :

    let root = xmlbuilder.create('foo', {
    version : '1.0' }).instruction('bar', 'random_key = "random_value"');
    root.end({'pretty': true});
    
    //Output :
    <?xml version="1.0">
    <?bar random_key = "random_value">
    <foo>
    ..
    </foo>