Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gj1118's avatar

Using Vue-resource to read xml file

Hi, I am using VUE resource to read xml file . I have the following code ready.

  methods: {
    getNewTitle () {
      this.$http.get('data/books.xml').then((response) => {
        console.log(response.body);
        this.getBookName(response.body);
      })
    }, 
    getBookName (xmlDoc) {
      var x, i, txt;
      console.log(xmlDoc);
      // xmlDoc = xml.responseXML;
      txt = "";
      x = xmlDoc.documentElement.childNodes;
      for (i = 0; i < x.length; i++) {
          if (x[i].nodeType == 1) {
              txt += x[i].nodeName + "<br>";
          }
      }
      return txt;
    }
  }

However, the xml is treated as a string and not as an xml and consequently in fails in the getBookName method whenever I try to do

x = xmlDoc.documentElement.childNodes;

Can you please help me out with this?

Thanks and Regards Gagan

0 likes
2 replies

Please or to participate in this conversation.