How to update XML file using xmldoc

23 Views Asked by At

I am trying to update the values of xml file. Below is the sample file. I am able to update firstName and lastName using this

document.getElementsByTagName("ns6:firstName")[0].childNodes[0].data='Abbey'
var XMLSerializer = require( 'xmldom' ).XMLSerializer;
var serializer = new XMLSerializer();
var xmlstring = serializer.serializeToString( document );
console.log( "xmlstring: \n" + xmlstring );

But I am not able to update flightNumber or origin or destination that way. The values are not updating

XML file:

    <ns6:flightSegment ns6:carrier="AA" ns6:flightNumber="1957" ns6:origin="SAT"     ns6:destination="DFW" ns6:departureDate="2023-03-17T12:22:00.000-05:00"/>
            <ns6:customerProfile>
                <ns6:firstName>JENNA</ns6:firstName>
                <ns6:lastName>JONES</ns6:lastName>

Can someone help how to update the XML file for the flightNumber?

0

There are 0 best solutions below