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_Meth od = objXMLDOM.selectNodes("Hea der/Sample PlusMethod ")
'Loops through Sample_And_Method nodeList collection
For Each recNodeSample_And_Method In recNodeListSample_And_Meth od
'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.g etElements ByTagName( "Analysis" )
__________________________ __________ __________ __________ __________ _____
Here's my ported version of the snippet:
__________________________ __________ __________ __________ __________ _____
Dim recNodeListSample_And_Meth od As XmlNodeList = docXML.SelectNodes("Header /SamplePlu sMethod")
For Each recNodeSample_And_Method As XmlNode In recNodeListSample_And_Meth od
'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.g etElements ByTagName( "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
Here's an original code snippet:
'_________________________
'Returns all Sample_And_Method nodes as nodeList collection
Set recNodeListSample_And_Meth
'Loops through Sample_And_Method nodeList collection
For Each recNodeSample_And_Method In recNodeListSample_And_Meth
'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.g
__________________________
Here's my ported version of the snippet:
__________________________
Dim recNodeListSample_And_Meth
For Each recNodeSample_And_Method As XmlNode In recNodeListSample_And_Meth
'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.g
__________________________
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.GetElementsByTagN ame(...)
Next
Dim oNode As IXMLDOMNode
Dim oElement As IXMLDOMElement
For Each oNode in oNodeList
Set oElement = oNode
oElement.GetElementsByTagN
Next
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.
Thanks again.
ASKER