Skip to content

dart:html XMLHttpRequest.responseXML throws an exception #1142

Closed
@munificent

Description

@munificent

If you do an AJAX request for an XML document and then try to access the document using .responseXML, it fails to wrap it. Example:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
  <script src="script.js"></script>
</head>
<body></body>
</html>


import('dart:html');

main() {
  XMLHttpRequest a = new XMLHttpRequest();
  a.open("GET", "http://localhost:8000/test.xml", true);
  a.on.readyStateChange.add(void b(e) {
    if (a.readyState == 4 && a.status == 200)
      a.responseXML;
  });
  a.send();
}

When it gets to responseXML, it fails in wrapDocument:

  static Document wrapDocument(raw) {
    if (raw === null) { return null; }
    if (raw.dartObjectLocalStorage !== null) {
      return raw.dartObjectLocalStorage;
    }
    switch (raw.typeName) {
      case "HTMLDocument":
        return new DocumentWrappingImplementation._wrap(raw, raw.documentElement);
      case "SVGDocument":
        return new SVGDocumentWrappingImplementation._wrap(raw);
      default:
        throw new UnsupportedOperationException("Unknown type:" + raw.toString());
    }
  }

The problem is that the raw object is a base Document (i.e. XML), not HTMLDocument or SVGDocument. My guess is that we'll want an explicit XMLDocument type in dart:html to handle this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-duplicateClosed in favor of an existing reportweb-librariesIssues impacting dart:html, etc., libraries

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions