XMLDocument Parsing Issue in VB.NET

R

rajesh

Hi,

I am trying to parse a xmldocument and to get value of a name tag
"techlanguage" is "vbdotnet".

Here i need to select the propername tag which is "techlanguage" and
the propervalue which is "vbdotnet"

Here is the structure of my XML

<?xml version="1.0" encoding="utf-8" ?>
<filters>
<filter customFilterType="">
<name>techdatabase</name>
<value>sqlserver</value>
</filter>
<filter customFilterType="">
<name>techlanguage</name>
<value>vbdotnet</value>
</filter>
<filter customFilterType="">
<name>techjava</name>
<value>j2ee</value>
</filter>
</filters>

Here is the code that tries to get the techlanguage as vbdotnet

Dim XMLValidateDoc As New XmlDocument
Dim Selectedtechlanguage As
System.Xml.XmlNode
Dim techlanguage As String
Try
XMLValidateDoc.Load(New
StringReader(Me.ucFilterSelector1.FilterXML.ToString()))
Selectedtechlanguage =
XMLValidateDoc.SelectSingleNode("///name[@name=techlanguage ]")
If Not Selectedtechlanguage Is Nothing
Then
'here i need to assign vbdotnet as
the techlanguage
' techlanguage = "vbdotnet" this is
what i exactly want
techlanguage =
Selectedtechlanguage.InnerText
End If

' bla bla

What is exact XPATH query i need to make to get the techlanguage valus
which is vbdotnet.please let me know what is the right code to do
this..

thanks
satish
 
Z

zacks

rajesh said:
Hi,

I am trying to parse a xmldocument and to get value of a name tag
"techlanguage" is "vbdotnet".

Here i need to select the propername tag which is "techlanguage" and
the propervalue which is "vbdotnet"

Here is the structure of my XML

<?xml version="1.0" encoding="utf-8" ?>
<filters>
<filter customFilterType="">
<name>techdatabase</name>
<value>sqlserver</value>
</filter>
<filter customFilterType="">
<name>techlanguage</name>
<value>vbdotnet</value>
</filter>
<filter customFilterType="">
<name>techjava</name>
<value>j2ee</value>
</filter>
</filters>

Here is the code that tries to get the techlanguage as vbdotnet

Dim XMLValidateDoc As New XmlDocument
Dim Selectedtechlanguage As
System.Xml.XmlNode
Dim techlanguage As String
Try
XMLValidateDoc.Load(New
StringReader(Me.ucFilterSelector1.FilterXML.ToString()))
Selectedtechlanguage =
XMLValidateDoc.SelectSingleNode("///name[@name=techlanguage ]")
If Not Selectedtechlanguage Is Nothing
Then
'here i need to assign vbdotnet as
the techlanguage
' techlanguage = "vbdotnet" this is
what i exactly want
techlanguage =
Selectedtechlanguage.InnerText
End If

' bla bla

What is exact XPATH query i need to make to get the techlanguage valus
which is vbdotnet.please let me know what is the right code to do
this..

thanks
satish

I think you are going to have to do a SelectNodes call on the filters
node list, and then do a SelectSingleNode from that list specifing
"filter/name" and "filter/value" to get the values out for them. But in
your case, you would need to do a For Each on the node list, get each
one, and look for the value of "filter/name" to see if you are on the
right one to retreive the "filter/value" for.
 
R

Rick

satish,

This will select the filter tags that have a 'name' child node with a value
of 'techlanguage' and a 'value' child node with a value of 'vbdotnet'

SelectSingleNode("filters/filter[name='techlanguage' and value='vbdotnet']

Below you are asking - SelectSingleNode("///name[@name=techlanguage ]").

This is asking for all nodes of 'name' node that have an attributed named
'name' with a value of 'techlanguage'. This does not exist in your
document.

rick
 

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