Question How do I convert an xml file (tags and all) to string?

NJCI

Member
Joined
May 9, 2011
Messages
8
Programming Experience
Beginner
I am writing a program in vb 2010. I need to protect the xml file which contains price information. It doesn't need to be hard-core encrypted, so I want to convert either the values in the elements, or the entire xml to Base64, then decode at runtime into my variables so that no one can look at the xml to read the information.

I'm testing by adding the value of each element to a listbox, encoding and adding to another listbox, then decoding into a third listbox. I tried
"For Each element As XElement In file.Root.Descendants()"
but that gives one line with all the values of an element (not what I want), then each one on a separate line (which is all I want). (I guess I could just find a way to ignore the first line?)

Another option is to convert the entire xml file to string (tags and all), but so far I have not been able to find an answer for this in VB.

I really only need to load one set of variables from one element at a time during runtime, so I think having the entire xml file encoded, and then decoding as the user makes selections, is the best option.

Please help!
 
Dim strAllText as String = IO.File.ReadAllText("YourXMLFile.xml")
 
Thank you. I ended up going a different direction to convert just the values in the tags, but I'm sure this will come in handy some day.
 
NJCI said:
I ended up going a different direction to convert just the values in the tags
Right, I was going to suggest using one of the XML Parsers to read an XML document but the above code will get you all the text inside any file.
 
Back
Top