how should this work ?? ( XML )

M

M. Posseth

Hello ,,,

i am currently bussy to learn some XML parsing however i have a slight
problem with it :)

in the below code i would expect the msgbox to give the result 0201 however
it returns an empty value

how should i handle this ???

( tryed all sorts of combinations with nodes and elements and attributes but
i do not get any values ..... aaaahrghhhh ;-) )







Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim x As String = "<?xml version=""1.0"" encoding=""iso-8859-1""?>" & vbCrLf
& _

"<tirep>" & vbCrLf & "<request>" & vbCrLf & "<cmd>0201</cmd>" & vbCrLf &
"<dsc>VS_GetBrands</dsc>" & vbCrLf & _

"<maxcount>200</maxcount>" & vbCrLf & "<IDsOnly></IDsOnly>" & vbCrLf &
"</request>" & vbCrLf & _

"<params>" & vbCrLf & "<session>{[GUID]}</session>" & vbCrLf &
"<BrandName>Au</BrandName>" & _

vbCrLf & "</params>" & vbCrLf & "</tirep>"

MsgBox(x)

Dim xmldoc As New XmlDocument

xmldoc.LoadXml(x)

With xmldoc.SelectSingleNode("tirep")

MsgBox(.Item("request").Item("cmd").Value)


End With

End Sub
 
S

Scott M.

Change your code to this:

With xmldoc.SelectSingleNode("tirep")
MsgBox(.Item("request").Item("cmd").firstChild.Value)
End With

remember that the text of an element is a child node of that element.
 
M

M. Posseth

Thanks ,,,

This worked great !

i also found this alternative method

MsgBox(xmldoc.GetElementsByTagName("cmd").Item(0).InnerText)

wich gives me the same result however , i do not trust this method as much
as i do yours :)

again thanks for your help

Michel



Scott M. said:
Change your code to this:

With xmldoc.SelectSingleNode("tirep")
MsgBox(.Item("request").Item("cmd").firstChild.Value)
End With

remember that the text of an element is a child node of that element.


M. Posseth said:
Hello ,,,

i am currently bussy to learn some XML parsing however i have a slight
problem with it :)

in the below code i would expect the msgbox to give the result 0201
however
it returns an empty value

how should i handle this ???

( tryed all sorts of combinations with nodes and elements and attributes
but
i do not get any values ..... aaaahrghhhh ;-) )







Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim x As String = "<?xml version=""1.0"" encoding=""iso-8859-1""?>" &
vbCrLf
& _

"<tirep>" & vbCrLf & "<request>" & vbCrLf & "<cmd>0201</cmd>" & vbCrLf &
"<dsc>VS_GetBrands</dsc>" & vbCrLf & _

"<maxcount>200</maxcount>" & vbCrLf & "<IDsOnly></IDsOnly>" & vbCrLf &
"</request>" & vbCrLf & _

"<params>" & vbCrLf & "<session>{[GUID]}</session>" & vbCrLf &
"<BrandName>Au</BrandName>" & _

vbCrLf & "</params>" & vbCrLf & "</tirep>"

MsgBox(x)

Dim xmldoc As New XmlDocument

xmldoc.LoadXml(x)

With xmldoc.SelectSingleNode("tirep")

MsgBox(.Item("request").Item("cmd").Value)


End With

End Sub
 
S

Scott M.

There are many ways to parse through XML using the W3C DOM and MS's
implementation of its own XML DOM. Just remember that when parsing through
XML, everything is considered a node and you must treat each item as such.


M. Posseth said:
Thanks ,,,

This worked great !

i also found this alternative method

MsgBox(xmldoc.GetElementsByTagName("cmd").Item(0).InnerText)

wich gives me the same result however , i do not trust this method as much
as i do yours :)

again thanks for your help

Michel



Scott M. said:
Change your code to this:

With xmldoc.SelectSingleNode("tirep")
MsgBox(.Item("request").Item("cmd").firstChild.Value)
End With

remember that the text of an element is a child node of that element.


M. Posseth said:
Hello ,,,

i am currently bussy to learn some XML parsing however i have a slight
problem with it :)

in the below code i would expect the msgbox to give the result 0201
however
it returns an empty value

how should i handle this ???

( tryed all sorts of combinations with nodes and elements and
attributes
but
i do not get any values ..... aaaahrghhhh ;-) )







Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim x As String = "<?xml version=""1.0"" encoding=""iso-8859-1""?>" &
vbCrLf
& _

"<tirep>" & vbCrLf & "<request>" & vbCrLf & "<cmd>0201</cmd>" & vbCrLf
&
"<dsc>VS_GetBrands</dsc>" & vbCrLf & _

"<maxcount>200</maxcount>" & vbCrLf & "<IDsOnly></IDsOnly>" & vbCrLf &
"</request>" & vbCrLf & _

"<params>" & vbCrLf & "<session>{[GUID]}</session>" & vbCrLf &
"<BrandName>Au</BrandName>" & _

vbCrLf & "</params>" & vbCrLf & "</tirep>"

MsgBox(x)

Dim xmldoc As New XmlDocument

xmldoc.LoadXml(x)

With xmldoc.SelectSingleNode("tirep")

MsgBox(.Item("request").Item("cmd").Value)


End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top