Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. XMLHttpRequest problem
Qt 6.11 is out! See what's new in the release blog

XMLHttpRequest problem

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chrisQT
    wrote on last edited by
    #1

    Hello everyone,

    experimenting with fresh install of QTSDK 1.1.3.
    I have this JS, which gets executed, on a mouse click:

    @onClicked: {
    var doc = new XMLHttpRequest();
    doc.onreadystatechange = function() {
    if (doc.readyState == XMLHttpRequest.DONE) {
    var a = doc.responseXML.documentElement;
    for (var ii = 0; ii < a.childNodes.length; ++ii) {
    console.log(a.childNodes[ii].nodeName);
    }
    }
    }
    doc.open("GET", "data.xml");
    doc.send();
    }@

    This is my data.xml

    @<?xml version="1.0" encoding="UTF-8"?>
    <document>
    <content>
    <item>
    <name>A Test Name</name>
    <id>1</id>
    </item>
    </content>
    </document>@

    This gives me this output on console:
    #text
    content
    #text

    Do I miss something? Any ideas, where this #text comes from?

    Regards,
    ChrisQT

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      As far as I understand the "extra" text nodes are caused by whitespace (spaces, newlines, etc). For example, the following file should only print "content" when traversing the DOM as you do above.

      @
      <document><content></content></document>
      @

      Regards,
      Michael

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chrisQT
        wrote on last edited by
        #3

        Thanks, that did it. So I have to escape my whole (valid) document to make it QML/JS valid?

        Regards,
        chrisQT

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          From what I can see whitespace #text nodes seem to be a common issue (e.g. http://stackoverflow.com/questions/1898640/ignoring-empty-xml-nodes-in-javascript ), so you may be able to find some helpful ways of dealing with them by searching around a bit.

          Regards,
          Michael

          [EDIT: fixed link, Volker]

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved