1

I am using NodeJs library called xmlbuilder-js for building dynamic XML output but I'm having a little difficulty removing the header of the XML Output. Following is my code sample

var xml = builder.create('root')
    .ele('parent')
    .ele('content')
    .dat('something').up()
    .up()
    .end()
console.log(xml) 

which produces following output

<?xml version="1.0"?>
<root>
<parent>
<content><![CDATA[something]]></content>
</parent><
</root>

Here I wanna remove the first line of the output which is called header that is <?xml version="1.0"?> and replace it with another line like <vast version="2.5"> but I'm confused how shall I do that. Can somebody please tell me with an example how to do so?

Point Networks
  • 1,071
  • 1
  • 13
  • 35
  • The XML format simply has this line on top. If you want to replace it with something else, it is not XML anymore (i.e. you are inventing a new format). If you really want to do this, consider replacing the text to what you would like it to be. Be aware that this might make the file unusable (since it is not XML) unless you write a reverse transformation that puts back the `` line. – T Tse Feb 12 '18 at 09:27
  • My suggestion is to make `` the root node. Your application might need a version and the root node is the place to put it. The XML version stays at `"1.0"`. Don't worry about it. – T Tse Feb 12 '18 at 09:30
  • Thanks, @ShioT for the suggestion. I understand that after removing the header my new markup could no longer be valid XML but my requirement is such that I have to somehow get rid of this header. – Point Networks Feb 12 '18 at 09:42
  • @Point Networks Any solution you found for removing the first line – Matt May 21 '19 at 13:46
  • well yeah, go through this issue https://github.com/oozcitak/xmlbuilder-js/issues/178 and its sollution – Point Networks May 22 '19 at 12:03

0 Answers0