Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XPath LT & GT: problems when comparing strings!

From: "Dimitre Novatchev" <dimitren@---.---.-->
To: NULL
Date: 9/5/2006 6:35:00 AM

In case you'd want to avoid extension functions altogether, see this:

    http://www.topxml.com/code/default.asp?p=3&id=v20010205033413

Cheers,
Dimitre Novatchev

"Dmitry Bond." <dima_ben@u...> wrote in message 
news:1157460142.211799.160310@i......
> 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.
> 




transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent