Click here to Skip to main content
13,290,261 members (50,926 online)

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: Uncheck this if you are not a bot Pin
jesarg7-Jul-14 11:49
memberjesarg7-Jul-14 11:49 
GeneralRe: Uncheck this if you are not a bot Pin
OriginalGriff8-Jul-14 2:38
protectorOriginalGriff8-Jul-14 2:38 
GeneralXPath oddity Pin
PIEBALDconsult3-Jul-14 9:15
memberPIEBALDconsult3-Jul-14 9:15 
GeneralRe: XPath oddity Pin
Richard Deeming3-Jul-14 9:39
professionalRichard Deeming3-Jul-14 9:39 
PIEBALDconsult wrote:
Of course, if you know of a way to test a node that uses neither SelectSingleNode nor SelectNodes, I'd be glad to see it.

How about this?
public static bool IsMatch(this System.Xml.XmlElement element, string predicate)
    return element.CreateNavigator().Matches("*[" + predicate + "]");

If you're going to be re-using the same predicate for a lot of elements, you might want to pre-compile it[^]:
public static bool IsMatch(this System.Xml.XmlElement element, XPathExpression compiledPredicate)
    return element.CreateNavigator().Matches(compiledPredicate);
var compiledPredicate = XPathExpression.Compile("*[" + predicate + "]");

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

GeneralRe: XPath oddity Pin
PIEBALDconsult3-Jul-14 10:21
memberPIEBALDconsult3-Jul-14 10:21 
GeneralComparisons... Pin
jan larsen1-Jul-14 0:30
memberjan larsen1-Jul-14 0:30 
GeneralRe: Comparisons... Pin
Bernhard Hiller1-Jul-14 21:56
professionalBernhard Hiller1-Jul-14 21:56 
GeneralRe: Comparisons... Pin
jan larsen4-Jul-14 3:46
memberjan larsen4-Jul-14 3:46 
GeneralRe: Comparisons... Pin
Bernhard Hiller4-Jul-14 4:15
professionalBernhard Hiller4-Jul-14 4:15 
GeneralRe: Comparisons... Pin
jan larsen9-Jul-14 23:28
memberjan larsen9-Jul-14 23:28 

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.

Advertise | Privacy |
Web02 | 2.8.171207.1 | Last Updated 12 Dec 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid