Reading xml attributes

P

Przemek

Hi,
I have problem with getting attributes from xml file. GetAttributes
method of XmlReader returns nothing. Here is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<budget
name="budgetest">
<Market.Research.PLN.Value
comments="blabla">156.3</Market.Research.PLN.Value>
<Technical.Analysis.PLN.Value
comments="hoh">125</Technical.Analysis.PLN.Value>
<Feasibility.Studies.PLN.Value
percentage="5"
comments="haha">14.065000000000001</Feasibility.Studies.PLN.Value>
</budget>

and here is my vb.code. I'm creating object "budget" and want fill its
fields with proper values:

Public Class Budget

'constructor and properties

Public Sub ReadBudget(ByVal projectFullName As String)
Dim path As String = projectFullName
Dim settings As New XmlReaderSettings
'settings.IgnoreComments = True
Dim reader As XmlReader = New XmlReader(path)
reader.Read()
reader.ReadStartElement("budget")
Me.Name = reader.GetAttribute("name")

reader.ReadStartElement("Market.Research.PLN.Value")
Me.MarketResearchComment = reader.GetAttribute("comments")
Me.MarketResearch = reader.ReadContentAsDouble()
reader.ReadEndElement()

reader.ReadStartElement("Technical.Analysis.PLN.Value")
Me.TechnicalAnalysisComment = reader.GetAttribute("comments")
Me.TechnicalAnalysis = reader.ReadContentAsDouble()
reader.ReadEndElement()

reader.ReadStartElement("Feasibility.Studies.PLN.Value")
Me.PercentageFeasibilityStudies = CDbl(reader.GetAttribute
("percentage")
Me.FeasibilityStudiesComment = reader.GetAttribute("comments")
Me.FeasibilityStudies = reader.ReadContentAsDouble()
reader.ReadEndElement()
reader.ReadEndElement()
End Sub
End Class

I'm receiving values from elements but I just can't get values for
attributes comments, percentage or name. What I'm doing wrong?

Przemek
 

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