Click here to Skip to main content
11,721,053 members (82,879 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, embarrasing 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.

 
GeneralUncheck this if you are not a bot Pin
PIEBALDconsult5-Jul-14 15:05
memberPIEBALDconsult5-Jul-14 15:05 
GeneralRe: Uncheck this if you are not a bot Pin
Brisingr Aerowing5-Jul-14 15:59
professionalBrisingr Aerowing5-Jul-14 15:59 
GeneralRe: Uncheck this if you are not a bot Pin
PIEBALDconsult6-Jul-14 8:27
memberPIEBALDconsult6-Jul-14 8:27 
GeneralRe: Uncheck this if you are not a bot Pin
d@nish 6-Jul-14 0:20
member d@nish 6-Jul-14 0:20 
GeneralRe: Uncheck this if you are not a bot Pin
PIEBALDconsult6-Jul-14 4:36
memberPIEBALDconsult6-Jul-14 4:36 
GeneralRe: Uncheck this if you are not a bot Pin
Bernhard Hiller6-Jul-14 21:17
professionalBernhard Hiller6-Jul-14 21:17 
GeneralRe: Uncheck this if you are not a bot Pin
Dennis_E6-Jul-14 23:43
professionalDennis_E6-Jul-14 23:43 
GeneralRe: Uncheck this if you are not a bot Pin
jesarg7-Jul-14 3:38
memberjesarg7-Jul-14 3:38 
GeneralRe: Uncheck this if you are not a bot Pin
PIEBALDconsult7-Jul-14 7:29
memberPIEBALDconsult7-Jul-14 7:29 
GeneralRe: Uncheck this if you are not a bot Pin
Dennis_E7-Jul-14 9:25
professionalDennis_E7-Jul-14 9:25 
GeneralRe: Uncheck this if you are not a bot Pin
jasonHall7-Jul-14 10:20
memberjasonHall7-Jul-14 10:20 
GeneralRe: Uncheck this if you are not a bot Pin
jesarg7-Jul-14 10:49
memberjesarg7-Jul-14 10:49 
GeneralRe: Uncheck this if you are not a bot Pin
OriginalGriff8-Jul-14 1:38
protectorOriginalGriff8-Jul-14 1:38 
GeneralXPath oddity Pin
PIEBALDconsult3-Jul-14 8:15
memberPIEBALDconsult3-Jul-14 8:15 
For something I'm working on, I want to test a given XmlElement with a provided XPath predicate to determine whether or not it's the droid node I'm looking for.

public static bool
IsMatch
(
  this System.Xml.XmlElement Element
,
  string                     Predicate
)                                     
{                                     
  return ( Element.SelectSingleNode ( "self::node()[" + Predicate + "]" ) != null ) ;
}

I wasted an hour trying to get .[predicate] to work.

System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
 
doc.LoadXml ( "<Foo Bar='Baz' />" ) ;
 
System.Console.WriteLine ( doc.DocumentElement.SelectSingleNode ( "." ).OuterXml ) ;
System.Console.WriteLine ( doc.DocumentElement.SelectSingleNode ( "self::node()[@Bar='Baz']" ).OuterXml ) ;
System.Console.WriteLine ( doc.DocumentElement.SelectSingleNode ( "self::*[@Bar='Baz']" ).OuterXml ) ;
System.Console.WriteLine ( doc.DocumentElement.SelectSingleNode ( ".[@Bar='Baz']" ).OuterXml ) ;

<Foo Bar="Baz" />
<Foo Bar="Baz" />
<Foo Bar="Baz" />
System.Xml.XPath.XPathException: '.[@Bar='Baz']' has an invalid token.

The book I have says . is equivalent to self::node(), but that's not true,
. returns a node, whereas self::node() returns a node-set, and you can only apply a predicate to a node-set. Sigh | :sigh:


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.
You'll never get very far if all you do is follow instructions.

GeneralRe: XPath oddity Pin
Richard Deeming3-Jul-14 8:39
professionalRichard Deeming3-Jul-14 8:39 
GeneralRe: XPath oddity Pin
PIEBALDconsult3-Jul-14 9:21
memberPIEBALDconsult3-Jul-14 9:21 
GeneralComparisons... Pin
jan larsen30-Jun-14 23:30
memberjan larsen30-Jun-14 23:30 
GeneralRe: Comparisons... Pin
Bernhard Hiller1-Jul-14 20:56
professionalBernhard Hiller1-Jul-14 20:56 
GeneralRe: Comparisons... Pin
jan larsen4-Jul-14 2:46
memberjan larsen4-Jul-14 2:46 
GeneralRe: Comparisons... Pin
Bernhard Hiller4-Jul-14 3:15
professionalBernhard Hiller4-Jul-14 3:15 
GeneralRe: Comparisons... Pin
jan larsen9-Jul-14 22:28
memberjan larsen9-Jul-14 22:28 
GeneralIIF to the rescue... Pin
Sander Rossel30-Jun-14 5:29
professionalSander Rossel30-Jun-14 5:29 
GeneralRe: IIF to the rescue... Pin
Bernhard Hiller30-Jun-14 20:38
professionalBernhard Hiller30-Jun-14 20:38 
GeneralRe: IIF to the rescue... Pin
Sander Rossel30-Jun-14 20:56
professionalSander Rossel30-Jun-14 20:56 
GeneralRe: IIF to the rescue... Pin
Bernhard Hiller30-Jun-14 21:35
professionalBernhard Hiller30-Jun-14 21:35 
GeneralRe: IIF to the rescue... Pin
Sander Rossel30-Jun-14 21:56
professionalSander Rossel30-Jun-14 21:56 
GeneralRe: IIF to the rescue... Pin
Bernhard Hiller1-Jul-14 20:57
professionalBernhard Hiller1-Jul-14 20:57 
GeneralRe: IIF to the rescue... Pin
Sander Rossel2-Jul-14 0:58
professionalSander Rossel2-Jul-14 0:58 
GeneralRe: IIF to the rescue... Pin
Nagy Vilmos30-Jun-14 23:43
professionalNagy Vilmos30-Jun-14 23:43 
GeneralRe: IIF to the rescue... Pin
Sander Rossel1-Jul-14 0:16
professionalSander Rossel1-Jul-14 0:16 
GeneralRe: IIF to the rescue... Pin
Richard Deeming1-Jul-14 2:33
professionalRichard Deeming1-Jul-14 2:33 
GeneralRe: IIF to the rescue... Pin
PaulLinton2-Jul-14 15:14
memberPaulLinton2-Jul-14 15:14 
GeneralRe: IIF to the rescue... Pin
Sander Rossel2-Jul-14 19:31
professionalSander Rossel2-Jul-14 19:31 
GeneralRe: IIF to the rescue... Pin
Jörgen Andersson5-Jul-14 20:02
professionalJörgen Andersson5-Jul-14 20:02 
GeneralStarting to page OS to disk! Pin
David O'Neil27-Jun-14 10:22
memberDavid O'Neil27-Jun-14 10:22 
GeneralChecking for empty guid Pin
Stepan Kobzey26-Jun-14 10:04
memberStepan Kobzey26-Jun-14 10:04 
GeneralRe: Checking for empty guid Pin
PIEBALDconsult26-Jun-14 10:13
memberPIEBALDconsult26-Jun-14 10:13 
GeneralRe: Checking for empty guid Pin
Stepan Kobzey26-Jun-14 10:16
memberStepan Kobzey26-Jun-14 10:16 
GeneralRe: Checking for empty guid Pin
PIEBALDconsult26-Jun-14 10:37
memberPIEBALDconsult26-Jun-14 10:37 
GeneralRe: Checking for empty guid Pin
Sander Rossel26-Jun-14 10:51
professionalSander Rossel26-Jun-14 10:51 
GeneralRe: Checking for empty guid Pin
PIEBALDconsult26-Jun-14 11:05
memberPIEBALDconsult26-Jun-14 11:05 
GeneralRe: Checking for empty guid Pin
Sander Rossel26-Jun-14 12:32
professionalSander Rossel26-Jun-14 12:32 
GeneralRe: Checking for empty guid Pin
OriginalGriff26-Jun-14 11:11
protectorOriginalGriff26-Jun-14 11:11 
GeneralRe: Checking for empty guid Pin
Sander Rossel26-Jun-14 12:32
professionalSander Rossel26-Jun-14 12:32 
GeneralRe: Checking for empty guid Pin
PIEBALDconsult27-Jun-14 4:37
memberPIEBALDconsult27-Jun-14 4:37 
GeneralRe: Checking for empty guid Pin
HomerTheGreat26-Jun-14 11:19
memberHomerTheGreat26-Jun-14 11:19 
GeneralRe: Checking for empty guid Pin
Bernhard Hiller27-Jun-14 0:11
professionalBernhard Hiller27-Jun-14 0:11 
GeneralRe: Checking for empty guid Pin
PIEBALDconsult27-Jun-14 4:37
memberPIEBALDconsult27-Jun-14 4:37 
GeneralRe: Checking for empty guid Pin
Bernhard Hiller27-Jun-14 0:06
professionalBernhard Hiller27-Jun-14 0:06 
GeneralRe: Checking for empty guid Pin
PIEBALDconsult27-Jun-14 4:38
memberPIEBALDconsult27-Jun-14 4:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web02 | 2.8.150901.1 | Last Updated 5 Sep 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid