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

<xs:element name="employee">
   <xs:element name="start" type="xs:date"/> 

and this code in VB Net CE 2015
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
Dim employee1 = root.<employee>.<start>.Value.ToString

but the same
Updated 20-Jan-19 10:47am
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:
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)

Good luck!

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