我如何使jQuery.parseXML在node.js中工作 [英] How can I make jQuery.parseXML work in node.js
问题描述
我正在尝试在node.js中使用jQuery parseXml
I am trying to use jQuery parseXml in node.js
我收到此错误:
Error: Invalid XML: <?xml version="1.0"...
但是问题不是不是在XML
But the problem is not in the XML
问题出在node-jquery.js中:
The problem is in node-jquery.js:
parseXML: function( data ) {
if ( typeof data !== "string" || !data ) {
return null;
}
var xml, tmp;
try {
if ( window.DOMParser ) { // Standard
tmp = new DOMParser();
xml = tmp.parseFromString( data , "text/xml" );
} else { // IE
xml = new ActiveXObject( "Microsoft.XMLDOM" );
xml.async = "false";
xml.loadXML( data );
}
} catch( e ) {
xml = undefined;
}
if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
jQuery.error( "Invalid XML: " + data );
}
return xml;
},
简单地说,在node.js中,没有 DOMParser ,也没有 ActiveXObject("Microsoft.XMLDOM")
To put it simply, in node.js, there is no DOMParser, and there is no ActiveXObject( "Microsoft.XMLDOM" )
由于我在Windows中工作,所以我希望ActiveXObject可以工作,但是不,它不能,jQuery吞下的实际错误不是无效的XML,因为未定义ActiveXObject:
Since I am working in windows, I would expect ActiveXObject to work, but no, it does not, the actual error swallowed by jQuery is not an invalid XML it is that ActiveXObject is not defined:
ReferenceError: ActiveXObject is not defined
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:
有任何解决方法吗?如何使jQuery.parseXML工作?
Any workarounds for this? How can I make jQuery.parseXML work?
推荐答案
我使用 xmldom 取得了巨大的成功.看一看.似乎像您期望$.parseXML
那样解析xml.我也遇到了jquery解析器的问题,尝试了一大堆之后切换到了这个解析器.
I've had great success using xmldom. Take a look. It seems to parse an xml just like you would expect $.parseXML
to. I was also having problems with the jquery parser and switched to this one after trying a bunch out.
这篇关于我如何使jQuery.parseXML在node.js中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!