none
Release Candidate: Did responseXML change at all? selectNodes isn't a method anymore...

    Question

  • We have the usual plain WinJS.xhr, and th request that comes back has the responseXML, but there is no selectNodes method.

    Example code:
    function processCategories(request) {
      var _categories = request.responseXML.selectNodes("//entry");
      ...yada yada

    There is a responseXml on the request just fine, but the responseXML doesn't have a selectNodes on it. Is there a new way to do things? This isn't in the Consumer > Release documentation.

    Friday, June 01, 2012 8:27 PM

Answers

  • Yes, you need to use querySelector instead of selectNodes as the data type of responseXML changed. It should be now something like:

    var categories = request.responseXML.querySelectorAll("entry");

    • Marked as answer by Harlequin Friday, June 01, 2012 9:58 PM
    Friday, June 01, 2012 9:08 PM

All replies

  • Yes, you need to use querySelector instead of selectNodes as the data type of responseXML changed. It should be now something like:

    var categories = request.responseXML.querySelectorAll("entry");

    • Marked as answer by Harlequin Friday, June 01, 2012 9:58 PM
    Friday, June 01, 2012 9:08 PM
  • Worked, thanks.

    Is there any reason why it doesn't show up as a method? Was looking at the responseXML properties/methods...

    Friday, June 01, 2012 10:03 PM
  • Usually that has to do with what IntelliSense is picking up, and there are probably still bugs in there especially with late-breaking changes like this. That is, the change might not have made it into the IntelliSense metadata in time for RP.
    Friday, June 01, 2012 10:07 PM
  • How do you do single nodes then? I'm not understanding any of this.

    Code example:
    var _baseCategory = _category.querySelectorAll("content")[0].childNodes[0];

    var _categoryID = _baseCategory.selectNodes("d:CategoryID")[0].text;
    var _categoryColor = _baseCategory.selectNodes("d:ColorCode")[0].text;
    var _diaplayName = _baseCategory.selectNodes("d:DisplayName")[0].text;

    Right now I think _baseCategory is working, but of course the selectNodes to get single items is broken. Bit upset this isn't in the breaking changes document...this has to affect almost everyone using xhr.

    Monday, June 04, 2012 9:36 PM
  • It looks like this:
    var _categoryID = _baseCategory.selectNodes("d:CategoryID")[0].text;

    ...turns into this:
    var _categoryID = _baseItem.getElementsByTagName("d:CategoryID")[0].textContent;

    textContent isn't in the conversion document either. I'm kind of baffled by the change from ".text" to ".textContent"...seems like a backward step.

    Monday, June 04, 2012 10:06 PM
  • All of this is because the underlying object type of the request.responseXML was changed, and that object has its own API.  Before it was an XML DOM object (out of the MSXML library), but it was changed to an HTML DOM object, hence the change in methods and properties.
    Tuesday, June 05, 2012 3:15 PM
  • It doesn't work for me . This's my code..

    WinJS.xhr({ url: urlText }).then(function (xml) {
            var restXML = xml.responseXML;
            var items = restXML.querySelectorAll("/news/item"); 
    bra bra bra...}

    It caused an "JavaScript runtime error: SyntaxError"

    Where I can find the correct code ? 

    Wednesday, June 06, 2012 8:57 AM
  • Check out this sample: XHR, handling navigation errors, and URL schemes sample (http://code.msdn.microsoft.com/windowsapps/XHR-handling-navigation-50d03a7a). I think the issue here is that the string you pass to querySelectorAll need to be a selector and not an xpath string. If I look in the sample, it uses a selector like this:

    var items = xml.querySelectorAll("rss > channel > item");

    So you might try "news > item" instead of "/news/item".

    Otherwise we'd need to know exactly where it's pointing to for the syntax error.

    Wednesday, June 06, 2012 4:34 PM
  • Oddly enough, querySelector and querySelectorAll do not work but selectNodes does...

    Not sure why though!

    Wednesday, June 06, 2012 8:50 PM
  • selectNodes works with the Consumer Preview bits, but not with the most recent Release preview bits. It's a specific breaking change; if selectNodes is working with a WinJS.xhr response, you must be on the CP build.
    Wednesday, June 06, 2012 9:14 PM
  • Yeah, just put that together... IT is building me a new machine now :P

    Thanks, Kraig!

    Wednesday, June 06, 2012 10:07 PM
  • I'm afraid this really doesn't seem like a change for the better. It's going to break a pile of code.
    Thursday, June 07, 2012 10:51 PM
  • I'm afraid this really doesn't seem like a change for the better. It's going to break a pile of code.
    ...and it's not documented anywhere either =(
    Friday, June 08, 2012 1:34 PM
  • I also have same problem, dont know how to select single nodes.

    For a simple RSS the code until Consumer Preview was:

    appendDiv(parent, item.selectNodes("title")[0].text, "postTitle");
    appendDiv(parent, item.selectNodes("pubDate")[0].text, "postDate");

    appendDiv(parent, item.selectNodes("description")[0].text, "postContent");

    Now the debugger breaks the code on above lines. Can anyone help what changes I need to do because its not documented anywhere. I have checked 

    Migrating your Windows 8 Consumer Preview app to Windows 8 Release Preview document but there is no documentation of this change.


    Mustzerone

    Sunday, June 10, 2012 8:45 AM
  • Replace selectNodes to querySelector and replace text to textContent

    Here is what worked for me:

     

    appendDiv(parent, items[0].querySelector("title").textContent, "postTitle");
                    appendDiv(parent, items[0].querySelector("pubDate").textContent, "postDate");
                    appendDiv(parent, items[0].querySelector("description").textContent, "postContent");

    Sunday, June 17, 2012 9:45 PM
  • And frankly, I have no idea why this change was even made?! XPath is the fastest way to select nodes in XML with namespaces and all. Why not simply add a new property responseHTML instead of *changing* the underlying implementation of responseXML to be a HTMLDOMDocument now?! Thats really bad bad API Design (again MSFT!). I hoped those days where over with WinRT...
    Monday, June 18, 2012 11:17 AM
  • Replace selectNodes to querySelector and replace text to textContent

    Here is what worked for me:

     

    appendDiv(parent, items[0].querySelector("title").textContent, "postTitle");
                    appendDiv(parent, items[0].querySelector("pubDate").textContent, "postDate");
                    appendDiv(parent, items[0].querySelector("description").textContent, "postContent");

    Replace items[0] to items[i] if you are using i as variable to loop through the items.
    Monday, June 18, 2012 2:26 PM