Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

porting from XMLDOM/classic asp to visual basic.net

Posted on 2005-04-27
4
Medium Priority
?
275 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:k3n51mm
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 2000 total points
ID: 13888084
Dim recNodeListSample_And_Method As XmlNodeList = docXML.SelectNodes("Header/SamplePlusMethod")
For Each recNodeSample_And_Method As XmlElement 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")

Next
0
 
LVL 1

Author Comment

by:k3n51mm
ID: 13891433
Thanks for the answer, this cleared the error. Why does it work?
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13892088
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
0
 
LVL 1

Author Comment

by:k3n51mm
ID: 13894628
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question