the easiest way you can do this is by doing this:
- switch the xml from .xml to .js
- make the whole content of the file as a string and put it inside a variable (use `` to select multiple lines)
- add at the end of your .js file (the one u just changed from .xml):
export default ;
- this will assure to export the variable as the main element of this file
and then where u want to access the content the file just use :
import from '<fileName(without extension)>'
- then u can use the variable containing your xml file as a text you can convert it to a json then parse it so u can have a valid json which is pretty flexible to work with
your code should look somthing like this:
xmlFile.js (used to be xmlFile.xml):
const xmlData = `<note>
<from>Jani</from>
<to>Tove</to>
<message>Remember me this weekend</message>
</note>`
export default xmlData;
file.js:
import xmlJs from 'xml-js';//import the library that handle xml/js conversion
import xmlData from './xmlFile';//getting the text
const jsontext = xmlJs.xml2json(xmlData)//turning it into a json formated text
const jsonObj = JSON.parse(jsontext)//parsing it into a json Object
best of luck