Link to home
Start Free TrialLog in
Avatar of k3n51mm
k3n51mm

asked on

porting from XMLDOM/classic asp to visual basic.net

I am porting code from a classic asp application to vb.net, converting the XMLDOM commands to system.xml.

Here's an original code snippet:
'_______________________________________________________________________  
                'Returns all Sample_And_Method nodes as nodeList collection
       Set recNodeListSample_And_Method = objXMLDOM.selectNodes("Header/SamplePlusMethod")
            
          'Loops through Sample_And_Method nodeList collection
           For Each recNodeSample_And_Method In recNodeListSample_And_Method
                   
               'Initializing all the variables for nect record
            strClient_Sample_ID = ""
            strClient_Method_ID = ""
            strAnalysis_Type = ""
            strLab_Sample_ID = ""
            strLab_ID = ""
            'Selecting Analysis based on Lab Analysis ID which links to Results table.
            'Returns all Analysis nodes as nodeList collection for a specific Sample_And_Method node       
               Set recNodeListAnalysis = recNodeSample_And_Method.getElementsByTagName("Analysis")
 _______________________________________________________________________                    

Here's my ported version of the snippet:
_______________________________________________________________________
            Dim recNodeListSample_And_Method As XmlNodeList = docXML.SelectNodes("Header/SamplePlusMethod")
            For Each recNodeSample_And_Method As XmlNode In recNodeListSample_And_Method
               'Initialize all variables for next record
                Dim strClient_Sample_ID As String = ""
                Dim strClient_Method_ID As String = ""
                Dim strAnalysis_Type As String = ""
                Dim strLab_Sample_ID As String = ""
                Dim strLab_ID As String = ""
                'Select Analysis based on Lab Analysis ID which links to Results table.
                'Returns all Analysis nodes as nodeList collection for a specific Sample_And_Method node       
                Dim recNodeListAnalysis As XmlNodeList = recNodeSample_And_Method.getElementsByTagName("Analysis")
_______________________________________________________________________

I'm getting an error in Visual Studio that says "getElementsByTagName is not a member of System.Xml.XmlNode".
However, I am concerned about searching the entire document for the "Analysis" nodes. I need them to be inside the subset of nodes already selected, and create a nodeList out of them as well. GetElementsByTagName is apparently a member of Xml.XmlDocument. I have already tried declaring  recNodeSample_And_Method as a nodeList instead, and it still didn't work. What command can I use in this case to make an equivalent selection? I have this issue in 2 other places in the existing code as well.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of k3n51mm
k3n51mm

ASKER

Thanks for the answer, this cleared the error. Why does it work?
it works because you are unboxing the XmlNode to the actual type which is XmlElement. It is the XmlElement that holds the GetElementsByTagName method(). In classic ASP, everything is variant and when you use the GetElementsByTagName, the VBScript engine looks through the actual objects to find the closest match. Whilst the actual object is IXMLDOMNode, you can cast the object back to IXMLDOMElement, in VB

Dim oNode As IXMLDOMNode
Dim oElement As IXMLDOMElement
For Each oNode in oNodeList
Set oElement = oNode
oElement.GetElementsByTagName(...)
Next
Avatar of k3n51mm

ASKER

Jeez, that's above my head for now. It's such a shame when all I have time for is to do it, not to learn it.
Thanks again.