OMEGA_ReD

How can i read/write program settings to an xml file.

thx!




Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET

OMEGA_ReD

i have an piece of code to write the xml wich works great!

but now i need to read the values to text boxes

Code Snippet

'Here iam creating an object of type XmlTextWrite to write to an xml file

Dim xmlWriter As New XmlTextWriter(XmlPath, System.Text.Encoding.UTF8)

xmlWriter.IndentChar = vbTab

xmlWriter.Indentation = 1

xmlWriter.Formatting = Formatting.Indented

xmlWriter.WriteStartElement("A")

xmlWriter.WriteElementString("p1000", "3,00")

xmlWriter.WriteElementString("p1100", "3,00")

xmlWriter.WriteElementString("p1200", "3,00")

xmlWriter.WriteElementString("p1300", "3,00")

xmlWriter.WriteElementString("p1400", "3,00")

xmlWriter.WriteEndElement()

xmlWriter.Close()






Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET

Martin Honnen

Are you using .NET 1.x or 2.0

As for reading/parsing XML the .NET framework provides lots of ways, there is XmlReader/XmlTextReader for fast forwards only pull parsing, there is XPathDocument/XPathNavigator for XPath based navigation and access, there is XmlDocument for DOM and XPath, there is XML deserialization.

With XmlDocument you can do e.g.

Code Snippet

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load("file.xml");

SomeTextBox.Text = xmlDocument.SelectSingleNode("A/p1000").InnerText;






Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET

OMEGA_ReD

im using VB.NET 2005 so it 2.0 thanks for your reply!

im going to use it for reading out settings and values for calculations made in my program






Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET


Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET

OMEGA_ReD

Thanks for your reply.

I will modify the xmlwriter code.

But the XMLRead function does not work.





Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET

Martin Honnen

OMEGA_ReD wrote:

But the XMLRead function does not work.

I am sure we can help but you will have to show us your relevant code and tell us which error you get.






Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET

OMEGA_ReD

I think i know whats the problem, the code you provided was written in C# and i am programming in VB.NET

thx!!






Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET

OMEGA_ReD






Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET

Martin Honnen

Here is the sample code translated to VB.NET:

Code Snippet

Dim XmlDoc As XmlDocument = New XmlDocument()

XmlDoc.Load("file.xml")

SomeTextBox.Text = _

XmlDoc.SelectSingleNode("A/p1000").InnerText






Re: XML and the .NET Framework Read/Write XML with value from textbox V.NET

sravanik

Hey OMEGA_ReD,

Have you looked at the new support for XML in Orcas

http://blogs.msdn.com/xmlteam/archive/2007/02/11/vb-9-0-xml-in-visual-studio-orcas-february-ctp.aspx

http://channel9.msdn.com/Showpost.aspx postid=289779

So, your problem could be solved like this,

Code Snippet

Dim myXml = <A>

<p1000> 3,00 </p1000>

<p1100> 3,00 </p1100>

<p1200> 3,00 </p1200>

<p1300> 3,00 </p1300>

<p1400> 3,00 </p1400>

</A>

Dim txtVal0 As String = myXml.<p1000>.Value

Dim txtVal1 As String = myXml.<p1100>.Value

Dim txtVal2 As String = myXml.<p1200>.Value

Dim txtVal3 As String = myXml.<p1300>.Value

Dim txtVal4 As String = myXml.<p1400>.Value