Column1 Column2 Column3 Column4
TextBox1.Text TextBox2.Text TextBox3.Text TextBox4.Text
etc...
When I send this out to XML, I get the following:
.
.
.
This is the code I'm using to generate the XML file:
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim fn As New Date
Dim tdyDate As Date = Date.Today()
Dim setts As New XmlWriterSettings()
setts.Indent = True
setts.IndentChars = " "
Dim writer As XmlWriter = XmlWriter.Create(My.Application.Info.DirectoryPath & "\" & tdyDate.ToString("MM'-'dd'-'yyyy") & ".xml", setts)
writer.WriteStartDocument()
writer.WriteStartElement("Meals")
For dr As Integer = 0 To DGV.Rows.Count - 2
writer.WriteStartAttribute(DGV.Columns(0).HeaderText.ToString, DGV.Rows(dr).Cells(0).Value.ToString)
writer.WriteElementString("Quantity", DGV.Rows(dr).Cells(1).Value.ToString)
writer.WriteElementString("Description", DGV.Rows(dr).Cells(2).Value.ToString)
writer.WriteElementString("Calories", DGV.Rows(dr).Cells(3).Value.ToString)
writer.WriteEndElement()
Next
writer.WriteEndElement()
writer.Flush()
writer.Close()
End Sub
Why am I getting the namespace attributes, instead of nodes named the same. In other words, why
VulpesPosted Jan 9, 2012, 6:04 AM
writer.WriteElementString(DGV.Columns(0).HeaderText.ToString, DGV.Rows(dr).Cells(0).Value.ToString)
VulpesPosted Jan 23, 2012, 11:04 AM
Here's an example which worked OK when I tried it just now.
The xml file, duane.xml, looks like this:
The code to load that into a DGV using LINQ to XML is as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim doc As XDocument = XDocument.Load("duane.xml")
Dim query = (From meal In doc.Descendants("Meals").Elements("Meal") Select
Quantity = CStr(meal.Element("Quantity")),
Description = CStr(meal.Element("Description")),
Calories = CStr(meal.Element("Calories"))).ToList()
DataGridView1.DataSource = query
End Sub
DuanePosted Jan 21, 2012, 11:43 PM
DuanePosted Jan 9, 2012, 3:53 PM