![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: XPath LT & GT: problems when comparing strings! XPath LT & GT: problems when comparing strings!To: NULL Date: 9/5/2006 5:42:00 AM Hello. Something strage happens when I try to compare a string value (value of XML attribute) with ">", "<" or ">=", "<=" operators. Looks like only "=" works for strings comparison in MSXML. :-( The following XPath queries always returns 0 nodes: //Order [ @Location <= 'M' ] //Order [ @Location >= 'M' ] but the query: //Order [ @Location = 'M100' ] returns 1 node in list. So, I assume that there are problems with "<" and ">" comparison operators in MSXML. But I need less- and greather- comparisons for strings! Could you please help me to solve this issue? Maybe there are some workarounds?... Below you can see test script (JScript), xml sample and output sample: ===test-script:begin=== var XmlName = "order.xml"; var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0"); xmlDoc.async = false; xmlDoc.resolveExternals = false; xmlDoc.load(XmlName); xmlDoc.setProperty("SelectionLanguage", "XPath"); if (xmlDoc.parseError.errorCode == 0) { WScript.Echo("XML successfully loaded."); var query = "//Order [ @Location = 'M100' ]"; var nodesList = xmlDoc.selectNodes(query); WScript.Echo(nodesList.length + " nodes selected by { " + query + " }"); query = "//Order [ @Location >= 'M' ]"; nodesList = xmlDoc.selectNodes(query); WScript.Echo(nodesList.length + " nodes selected by { " + query + " }"); query = "//Order [ @Location <= 'M' ]"; nodesList = xmlDoc.selectNodes(query); WScript.Echo(nodesList.length + " nodes selected by { " + query + " }"); } ===test-script:end=== ===order.xml:begin=== <Order Location="M100"/> ===order.xml:end=== ===script console output sample:begin=== XML successfully loaded. 1 nodes selected by { //Order [ @Location = 'M100' ] } 0 nodes selected by { //Order [ @Location >= 'M' ] } 0 nodes selected by { //Order [ @Location <= 'M' ] } ===script console output sample:end=== WBR, Dmitry. ps. Tested with MSXML 4.0sp2 and 6.0. | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
