Given the xml below why does the first selectsinglenode call not work but the second one does? Are the single quotes specifying a string type or something?
Dim dbglvlnode As Xml.XmlNode = doc.SelectSingleNode(String.Format("Config/Scanner[DeviceID = '{0}']/DebugLevel", XMLstuff.DeviceID))
Dim dbglvlnode As Xml.XmlNode = doc.SelectSingleNode(String.Format("Config/Scanner[DeviceID = {0}]/DebugLevel", XMLstuff.DeviceID))
<?xml version="1.0" standalone="yes"?>
<Config>
<Scanner>
<!--Test Scanner-->
<DeviceID>00199</DeviceID>
<DeviceNumber>0099</DeviceNumber>
<DebugLevel>10</DebugLevel>
</Scanner>
</Config>
Your first approach would lead to an XPath expression sort of like this:
This would return the DebugLevel element of the first Scanner in Config for which the DeviceID element has textual value
00199Your second approach would lead to an XPath expression like this:
This would return the DebugLevel element of the first Scanner in Config for which the DeviceID element has the numeric value
00199.The difference is that the first approach would only match
00199exactly, so ifXMLstuff.DeviceIDis an integer or a string with value199, it won’t work. The second approach will work as long as the element’s content evaluates to an integer with the right value. So yes, the single quotes identify that right-hand portion of the comparison as text.XPath is rather lenient in converting data types and doing comparisons.