Hi all,
I've got an xml file that something like this:
Etc etc etc.Code:<?xml version="1.0" encoding="utf-8" ?> <AllBanks xmlns="http://tempuri.org/BankNames.xsd"> <Bank> <Name>MyBank</Name> <FromCode>000000</FromCode> <ToCode>051000</ToCode> </Bank> <Bank> <Name>Bank1</Name> <FromCode>090061</FromCode> <ToCode>092564</ToCode> </Bank> <Bank> <Name>Bank2</Name> <FromCode>100909</FromCode> <ToCode>199905</ToCode> </Bank> <Bank> <Name>Bank3</Name> <FromCode>200106</FromCode> <ToCode>291364</ToCode> </Bank> <Bank> <Name>Bank4</Name> <FromCode>301105</FromCode> <ToCode>337005</ToCode> </Bank> </AllBanks>
I am creating a function that where a BranchCode will be passed into it for eg: 35656
The function needs to search in which range does the passed variable reside, then return the Name field.
What would be the best way of doing this? Currently I constructed the following. (It's really crappy I know...)
VB Code:
Function FindBankName(ByRef BranchCode As Object) As Object Dim doc As New Xml.XmlDocument Dim node As Xml.XmlNode Dim child As Xml.XmlNode Dim BankName As String BankName = "" doc.Load(Environment.CurrentDirectory & "\banks.xml") node = doc.DocumentElement for each Child.selectSingleNode(child::Bank) If (BranchCode >= node.SelectNodes(attribute::FromCode)) And (BranchCode <= node.SelectSingleNodes(Attribute::ToCode)) Then BankName = node.SelectNodes() End If Next 'hard-code property value for testing 'child = node.SelectSingleNode(If (BranchCode >="00000") And (BranchCode <= "409999")) End Function
I have never queried a XML file before, so this is my first try... Please Help




Reply With Quote