2

We are currently in the preparating for upgrading CRM 2011 with UR 12, and there are a few pieces of javascript that might break after the upgrade.

The XML related functions are some of the ones highlighted as potential code. So I would like to replace these functions with JQuery equivalent, but do not have much idea about jQuery

Assuming that 'result' is a XML response from xmlhttprequest, how do we convert the following code to use jquery

result.selectNodes("//EntityMetadata/DisplayName/LocLabels/LocLabel/Label");

will something like

$(result).find(("//EntityMetadata/DisplayName/LocLabels/LocLabel/Label");
j0k
  • 22,600
  • 28
  • 79
  • 90
Rajesh
  • 449
  • 2
  • 9
  • 22

2 Answers2

0

It appears that jQuery once had rudimentary XPath support. However, this does not seem to be the case anymore. You may find Cross-browser XPath implementation in JavaScript interesting.

Also, there's no requirement that the result of XMLHttpRequest be XML. It could be text, JSON, binary data, etc.

Community
  • 1
  • 1
jensgram
  • 31,109
  • 6
  • 81
  • 98
0

Despite this takes not your question regarding jQuery into account, it shows a way described in the CRM SDK.

Take a look at the JavaScript Best Practices article. This article links to a sample where a compatible implementation of selectNode is shown

function _selectNodes(node, XPathExpression) {
  if (typeof (node.selectNodes) != "undefined") {
   return node.selectNodes(XPathExpression);
  }
  else {
   var output = [];
   var XPathResults = node.evaluate(XPathExpression, node, _NSResolver, XPathResult.ANY_TYPE, null);
   var result = XPathResults.iterateNext();
   while (result) {
    output.push(result);
    result = XPathResults.iterateNext();
   }
   return output;
  }
 };
ccellar
  • 10,326
  • 2
  • 38
  • 56