Click here to Skip to main content
15,886,873 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: When Did That Happen? Pin
  Forogar  16-Jul-18 2:18
professional  Forogar  16-Jul-18 2:18 
GeneralRe: When Did That Happen? Pin
David A. Gray16-Jul-18 10:23
David A. Gray16-Jul-18 10:23 
GeneralRe: When Did That Happen? Pin
RossMW19-Jul-18 16:25
professionalRossMW19-Jul-18 16:25 
GeneralRe: When Did That Happen? Pin
Richard Deeming16-Jul-18 8:28
mveRichard Deeming16-Jul-18 8:28 
GeneralXPath string comparisons Pin
kmoorevs12-Jul-18 5:46
kmoorevs12-Jul-18 5:46 
GeneralRe: XPath string comparisons Pin
Richard Deeming12-Jul-18 6:27
mveRichard Deeming12-Jul-18 6:27 
GeneralRe: XPath string comparisons Pin
kmoorevs12-Jul-18 7:52
kmoorevs12-Jul-18 7:52 
GeneralRe: XPath string comparisons Pin
Richard Deeming12-Jul-18 9:48
mveRichard Deeming12-Jul-18 9:48 
OK, the "less than" and "greater than" operators don't work for strings, as per the specification:
When neither object to be compared is a node-set and the operator is <=, <, >= or >, then the objects are compared by converting both objects to numbers and comparing the numbers according to IEEE 754.

I'd be very surprised if that wasn't also the case with the old MSXML library. But then again, it was written by 90's Microsoft - they weren't the best at sticking to the specifications! Big Grin | :-D

There's no obvious sign of Microsoft implementing XPath 2 or 3 in .NET; there's an open suggestion from 2013[^] which is "under consideration", with no sign of any action.

There's also an MSDN blog post from 2004[^] suggesting they would be working on XQuery instead. Again, no sign of any progress on that front.

It's also worth pointing out that you can't use the less than or greater than operators on strings in .NET code either. Instead, you have to use the CompareTo method.

You can get close by using LINQ to XML, but that obviously requires you to load the entire document into memory:
C#
var doc = XDocument.Parse(@"<?xml version='1.0'?>  
<bookstore xmlns=""urn:newbooks-schema"">  
  <book genre=""novel"" style=""hardcover"" publish_date=""1825-04-02"">  
  ...
</bookstore>");

var nodes = doc.Descendants(doc.Root.Name.Namespace + "book")
    .Where(el => ((string)el.Attribute("publish_date")).CompareTo("1901-10-29") >= 0);

// Or:
var nodes = doc.Descendants(doc.Root.Name.Namespace + "book")
    .Where(el => (DateTime)el.Attribute("publish_date") >= new DateTime(1901, 10, 29));




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralTwo easy lines for web copy to clipboard Pin
raddevus6-Jul-18 8:59
mvaraddevus6-Jul-18 8:59 
GeneralRe: Two easy lines for web copy to clipboard Pin
Nelek9-Jul-18 1:45
protectorNelek9-Jul-18 1:45 
GeneralOuternet Pin
Dr.Walt Fair, PE6-Jul-18 5:24
professionalDr.Walt Fair, PE6-Jul-18 5:24 
GeneralRe: Outernet Pin
Nelek6-Jul-18 7:18
protectorNelek6-Jul-18 7:18 
GeneralRe: Outernet Pin
Dr.Walt Fair, PE6-Oct-18 11:35
professionalDr.Walt Fair, PE6-Oct-18 11:35 
GeneralRe: Outernet Pin
Nelek6-Oct-18 23:49
protectorNelek6-Oct-18 23:49 
GeneralConsole Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
David A. Gray3-Jul-18 8:46
David A. Gray3-Jul-18 8:46 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
Randor 3-Jul-18 9:40
professional Randor 3-Jul-18 9:40 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
Rick York3-Jul-18 11:19
mveRick York3-Jul-18 11:19 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
David A. Gray3-Jul-18 15:08
David A. Gray3-Jul-18 15:08 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
Randor 3-Jul-18 15:54
professional Randor 3-Jul-18 15:54 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
David A. Gray4-Jul-18 10:16
David A. Gray4-Jul-18 10:16 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
Randor 4-Jul-18 14:24
professional Randor 4-Jul-18 14:24 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
David A. Gray5-Jul-18 6:04
David A. Gray5-Jul-18 6:04 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
Randor 5-Jul-18 8:42
professional Randor 5-Jul-18 8:42 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
David A. Gray5-Jul-18 11:51
David A. Gray5-Jul-18 11:51 
GeneralRe: Console Window of Visual Studio 2017 Debugger Answers F10 with Full Screen 43-Line Display Pin
Randor 5-Jul-18 12:31
professional Randor 5-Jul-18 12:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.