|
-
Jun 21st, 2007, 10:08 AM
#1
Thread Starter
Hyperactive Member
[2005] VB5/6 to VB.NET help?
Hey,
I was hoping someone could help out with converting this code:
Code:
Public Function LoadXMLNode()
Dim xmlDoc As DOMDocument30
Dim intCounter As Integer
Set xmlDoc = New MSXML2.DOMDocument30
Me.TxtXMLOut.Text = ""
xmlDoc.loadXML Me.TxtXML.Text
Call RecurseChildNodes(xmlDoc, xmlDoc.childNodes)
Set xmlDoc = Nothing
End Function
Public Function RecurseChildNodes(xmlDoc As MSXML2.DOMDocument30, childNode As IXMLDOMNodeList)
Dim CurrChildNode As IXMLDOMNodeList
Dim intNodeCounter As Integer
Set CurrChildNode = childNode
For intNodeCounter = 0 To CurrChildNode.length - 1
If CurrChildNode.length > 0 Then
Set childNode = CurrChildNode.Item(intNodeCounter).childNodes
If childNode.length > 0 Then
RecurseChildNodes xmlDoc, childNode
Me.TxtXMLOut.Text = Me.TxtXMLOut.Text & CurrChildNode.Item(intNodeCounter).nodeName & "= " & CurrChildNode.Item(intNodeCounter).nodeTypedValue & vbCrLf
End If
End If
Next intNodeCounter
End Function
The code is in VB5/6 but i need to get it to vb.net 2005, could anyone help me out? im sure theres a simple new rule to it or something.
I get errors saying:
MSXML2.DOMDocument30 is not defined
DOMDocument30 is not defined
IXMLDOMNodeList is not defined
Thanks for any help
lee
If a post has been usefull then Rate it! 
-
Jun 21st, 2007, 10:25 AM
#2
Hyperactive Member
Re: [2005] VB5/6 to VB.NET help?
Try this. I just stuck it in the IDE and it has no errors.
vb.net Code:
Public Function LoadXMLNode()
Dim xmlDoc As Xml.XmlDocument
xmlDoc = New Xml.XmlDocument()
Me.TxtXMLOut.Text = ""
xmlDoc.loadXML(Me.TxtXML.Text)
Call RecurseChildNodes(xmlDoc, xmlDoc.childNodes)
xmlDoc = Nothing
Return Nothing
End Function
Public Function RecurseChildNodes(ByVal xmlDoc As Xml.XmlDocument, ByVal childNode As Xml.XmlNodeList)
Dim CurrChildNode As Xml.XmlNodeList
Dim intNodeCounter As Integer
CurrChildNode = childNode
For intNodeCounter = 0 To CurrChildNode.Count - 1
If CurrChildNode.Count > 0 Then
childNode = CurrChildNode.Item(intNodeCounter).ChildNodes
If childNode.Count > 0 Then
RecurseChildNodes(xmlDoc, childNode)
Me.TxtXMLOut.Text = Me.TxtXMLOut.Text & CurrChildNode.Item(intNodeCounter).Name & "= " & CurrChildNode.Item(intNodeCounter).NodeType & vbCrLf
End If
End If
Next intNodeCounter
Return Nothing
End Function
-
Jun 21st, 2007, 11:11 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] VB5/6 to VB.NET help?
Using that code didnt work right, i put in the xml:
<Clients>
<Client>
<NameInfo>
<NameFirst>Mickey</NameFirst>
<NameLast>Mouse</NameLast>
<NamePrefix>Mr.</NamePrefix>
</NameInfo>
<NameInfo>
<NameFirst>Donald</NameFirst>
<NameLast>Duck</NameLast>
<NamePrefix>Mr.</NamePrefix>
</NameInfo>
</Client>
</Clients>
The result i get is incorrect:
NameFirst= 1
NameLast= 1
NamePrefix= 1
NameInfo= 1
NameFirst= 1
NameLast= 1
NamePrefix= 1
NameInfo= 1
Client= 1
Clients= 1
im unsure if im doing anything wrong or not :s
If a post has been usefull then Rate it! 
-
Jun 21st, 2007, 11:16 AM
#4
Hyperactive Member
Re: [2005] VB5/6 to VB.NET help?
try this..
vb.net Code:
CurrChildNode.Item(intNodeCounter).Value
'instead of CurrChildNode.Item(intNodeCounter).Name
I never used xml before. but this should give you the right response that you are looking for.. the .name looks for a Name="" field, and i believe the .value will give you what you want.
-
Jun 21st, 2007, 11:18 AM
#5
Re: [2005] VB5/6 to VB.NET help?
Vblee,
that's not VB5/6 code. It's already in VB 2005.
I think the problems are simply caused because you are missing a reference to the microsoft MSXML2 namespace (if not more). Add the appropriate reference(s) and the problems will be taken care of.
Last edited by stimbo; Jun 21st, 2007 at 11:22 AM.
-
Jun 21st, 2007, 11:19 AM
#6
Thread Starter
Hyperactive Member
Re: [2005] VB5/6 to VB.NET help?
That gets me:
= 1
= 1
= 1
= 1
= 1
= 1
= 1
= 1
= 1
= 1
If a post has been usefull then Rate it! 
-
Jun 21st, 2007, 11:25 AM
#7
Hyperactive Member
Re: [2005] VB5/6 to VB.NET help?
oh, my bad.. I was looking at that the wrong way..
change .Value back to .Name
try this where .NodeType is
kind of confusing but may work.
vb.net Code:
CurrChildNode.Item(intNodeCounter).GetAttribute(CurrChildNode.Item(intNodeCounter).Name().ToString)
if getAttribute does not work try GetElementsByTagName()
sorry nothing is working.. not really an xml guru.
-
Jun 21st, 2007, 11:52 AM
#8
Thread Starter
Hyperactive Member
Re: [2005] VB5/6 to VB.NET help?
 Originally Posted by stimbo
Vblee,
that's not VB5/6 code. It's already in VB 2005.
I think the problems are simply caused because you are missing a reference to the microsoft MSXML2 namespace (if not more). Add the appropriate reference(s) and the problems will be taken care of.
I have tried that and it doesnt work.
NPassero i get an error with that line, "GetAttribute" is not a member of "system.xml.xmlnode"
If a post has been usefull then Rate it! 
-
Jun 21st, 2007, 11:54 AM
#9
Hyperactive Member
Re: [2005] VB5/6 to VB.NET help?
Did you try the GetElementByTagName()
if not, i am fresh out of ideas, and someone who is really familiar with XML needs to step in.
-
Jun 21st, 2007, 11:56 AM
#10
Thread Starter
Hyperactive Member
Re: [2005] VB5/6 to VB.NET help?
Nope nothing, thanks for your help, hope someone with more knowledge of xml can help.
If a post has been usefull then Rate it! 
-
Jun 21st, 2007, 12:24 PM
#11
Re: [2005] VB5/6 to VB.NET help?
I notice that what NPassero suggested in post #2 got you almost the right answer, except that it returned the type, which was not what you wanted.
What was it that your code returned? Did you get an error, or did you get incorrect information, and if so, what?
I'm leaning towards either Stimbo is on the right track, or this line is wrong:
CurrChildNode.Item(intNodeCounter).nodeTypedValue
but it depends on what you were getting originally.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|