By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

XML Attribute Value

P: n/a
Hi All

I have a xml file in the format below:
<root>
<selection-attr select-style="dropdown" attr="a123">
<value code="A">Responce A</value>
<value code="B">Responce B</value>
<value code="C">Responce C</value>
<value code="D">Responce D</value>
<caption>Question Text</caption>
</selection-attr>
</root>

How do I go about extracting the attr vale from :
<selection-attr select-style="dropdown" attr="a123">

I am trying to read the value a123.

Any assistance would be appreciated.

Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Have you looked into XPath?

Use an XML document to load the XML file and then using XPath, you can
iterate through the xml file and extract the attribute value.

I just reformatted my machine and VS is not installed right now so I can't
give you a working example right off but I know there are examples in MSDN.

I will try this out in the morning and post some code for you if your
question has not already been answered by that time.

--
Gerry O'Brien
Visual Basic.NET MVP
"David" <Da***@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Hi All

I have a xml file in the format below:
<root>
<selection-attr select-style="dropdown" attr="a123">
<value code="A">Responce A</value>
<value code="B">Responce B</value>
<value code="C">Responce C</value>
<value code="D">Responce D</value>
<caption>Question Text</caption>
</selection-attr>
</root>

How do I go about extracting the attr vale from :
<selection-attr select-style="dropdown" attr="a123">

I am trying to read the value a123.

Any assistance would be appreciated.

Thanks

Nov 21 '05 #2

P: n/a
David,

Does this little sample I once made help you?

\\\\
Dim xmlString As String = "<department>" & _
"<employee name=""ABC"" age=""31"" sex=""male""/>" & _
"<employee name=""CDE"" age=""40"" sex=""male""/></department>"
Dim sr As New System.IO.StringReader(xmlString)
Dim doc As New Xml.XmlDocument
doc.Load(sr)
'or just in this case doc.LoadXML(xmlString)
Dim reader As New Xml.XmlNodeReader(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "employee" Then
MessageBox.Show(reader.GetAttribute("name"))
End If
End Select
End While
///

I hope this helps a little bit?

Cor
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.