Click here to Skip to main content
15,902,636 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
David A. Gray13-Jul-18 10:51
David A. Gray13-Jul-18 10:51 
GeneralRe: When Did That Happen? Pin
#realJSOP15-Jul-18 23:52
professional#realJSOP15-Jul-18 23:52 
GeneralRe: When Did That Happen? Pin
Eddy Vluggen16-Jul-18 0:13
professionalEddy Vluggen16-Jul-18 0:13 
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 
I spent way too long yesterday discovering that XPath 1.0 does not support string comparisons for anything but equal as the args are automatically converted to number...not much use when you are trying to filter an xml document with a date attribute!...or any string which doesn't convert to number) The weird thing about this is that this was VB6 code I am migrating...meaning, it works fine with ancient XML libs, but not a modern framework. (currently targeting 4.0) Such is progress! Laugh | :laugh: I guess I'm used to going forward, not backward! Smile | :)


They may have fixed/added this in XPath 2.0 which I think is available under .NET 4.6.2 or something. I chose another method not involving XPath once I discovered why no results were being returned. It was the hours spent cursing and swearing, not understanding why something that looks like it should work doesn't. No error, just no results. It was easy to understand why once I knew that the rules had changed.

For clarity, I'm providing a sample xml doc and code:
The sample xml document was taken from MS sample code. I only added the publish_date attribute as this was akin to my actual usage.
<xml version='1.0'?>  
<bookstore xmlns="urn:newbooks-schema">  
  <book genre="novel" style="hardcover" publish_date="1825-04-02">  
    <title>The Handmaid's Tale</title>  
    <author>  
      <first-name>Margaret</first-name>  
      <last-name>Atwood</last-name>  
    </author>  
    <price>19.95</price>  
  </book>  
  <book genre="novel" style="other" publish_date="1901-10-29">  
    <title>The Poisonwood Bible</title>  
    <author>  
      <first-name>Barbara</first-name>  
      <last-name>Kingsolver</last-name>  
    </author>  
    <price>11.99</price>  
  </book>  
  <book genre="novel" style="paperback" publish_date="1965-06-10">  
    <title>The Bean Trees</title>  
    <author>  
      <first-name>Barbara</first-name>  
      <last-name>Kingsolver</last-name>  
    </author>  
    <price>5.99</price>  
  </book>  
</bookstore>  


and now, the code:
Dim xmlDoc As New System.Xml.XmlDocument
Dim xmlNodes As System.Xml.XmlNodeList
Dim root As System.Xml.XmlNode
xmlDoc.Load("..\bookstore.xml")
Dim nsmgr As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(xmlDoc.NameTable)
nsmgr.AddNamespace("bk", "urn:newbooks-schema")
root = xmlDoc.DocumentElement
'this returns 1 node/record
xmlNodes = root.SelectNodes("descendant::bk:book[@publish_date = '1901-10-29']", nsmgr)

Debug.Print(xmlNodes.Count)
'this returns 0 nodes/records
xmlNodes = root.SelectNodes("descendant::bk:book[@publish_date > '1901-01-01']", nsmgr)
Debug.Print(xmlNodes.Count)

"Go forth into the source" - Neal Morse


modified 12-Jul-18 13:48pm.

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 
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 

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.