Click here to Skip to main content
15,917,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this xml file
XML
<?xml version="1.0" encoding="UTF-8"?>

<xs:element name="employee">
<xs:complexType>
   <xs:element name="start" type="xs:date"/> 
     <start>2002-09-24</start>
  </xs:complexType>
</xs:element>

and this code in VB Net CE 2015
VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Dim root As XElement = XDocument.Load("C:\Users\supervisor\Documents\Visual Studio 2015\Projects\mdi\mdi\tameio3.xml").Root
       Dim employee1 = date.Parse(root.<employee>.<start>.Value).ToString
       TextBox1.Text = employee1
   End Sub


when I push the button the app just freezes any help or ideas on how to read the xml element in a textbox?

What I have tried:

the above solution tried this too
VB
Dim employee1 = root.<employee>.<start>.Value.ToString

but the same
Posted
Updated 20-Jan-19 9:47am
Comments
Richard Deeming 22-Jan-19 9:14am    
Is that your entire XML file? You're missing the namespace declaration for the xs: prefix.

You're also looking for elements that don't exist. There is no <employee> element; instead, there is an <xs:element> with an attribute called name that contains the value "employee".

1 solution

There's few ways to read xml. Please, follow the instruction from past answer: Read xml node from give xml file[^]

I prefer to use XDocument + Linq:
VB.NET
Dim xdoc As XDocument = XDocument.Load("C:\Users\supervisor\Documents\Visual Studio 2015\Projects\mdi\mdi\tameio3.xml")
Dim employees = xdoc.Descendants("employee").ToList()
For Each ele As XElement In employees
    Console.WriteLine("{0} - {1}", ele.Name, ele.Value)
Next


Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900