0

I am doing VueJS 3 project with Vuex to deel with the data. For the moment I read my data on a JSON file.

import axios from 'axios'
import { createStore } from 'vuex'
export default createStore({
  state: {
    data: [],
  },
  actions: {
    getData({commit}){
      axios.get('http://localhost:8080/data/mock.json')
      .then(res => {
        commit('SET_DATA', res.data)
      })
    },
  },
  mutations: {
    SET_DATA(state, data){
      state.data = data.data;
    },
  },
  modules: {
  }
})

I would like to do the same thing but with an XML file, not a JSON. Do you know if it's possible ? With axios for example. Thanks

Kate P
  • 37
  • 8

1 Answers1

0

You can use xml2Json to parse the XML to JSON so you can handle the data in Javascript easily.

Example:

var parser = require('xml2json');
 
var xml = "<foo attr=\"value\">bar</foo>";
 
// xml to json
var json = parser.toJson(xml);
Mikel Granero
  • 379
  • 6
  • 15
  • I tried your solution but the command "npm install xml2json" didn't work : lots of errors beginning by "ERR ! fin Python ..." – Kate P Aug 05 '21 at 08:10
  • Check this solution for the Python errors for xml2Json. By installin these 2 npm packages it should work: https://stackoverflow.com/questions/51617241/xml2json-install-error-cant-find-python-executable-you-can-set-the-python-env-v – Mikel Granero Aug 05 '21 at 08:17