Un-escaping XML?

Hi, just playing around with some XML stuff in c# and have a problem un-escaping a SQL Connection string...

The XML is as follows:

< xml version="1.0" encoding="utf-8" >
<dbSettings>
<connectionString>
User ID = ****;Password = ****;Integrated Security = False;Initial Catalog = CMS;Data Source = vaio\sqlexpress
</connectionString>
</dbSettings>

I'm using a nodeiterator and fetching the required node, but when I read it back out using NodeIter.Current.Value.Trim() the backslash between "vaio" and "sqlexpress" as been escaped so I get "\\" - which obviously fails when I try and open a connection to the database.

The string also has various \n\r\t type chars in it too which I think the trim gets rid of.

The question is, how do I get back to having just one slash in the string

Thanks


Answer this question

Un-escaping XML?

  • D_

    They don't make it easy with some things :-)

  • hrlevy

    Thanks for the reply...

    If I add a watch statement to the var that holds the trimmed connection string (from the XML document) then it has two backslashes in it....

  • cmille19

    Are you sure When you "view" strings in Visual Studio it escapes these types of characters. Where are you viewing the string data

  • Hugohugo37

    Yes, you will see "escapable" characters with escapes in the watch window. If you output it to the debug output, or view it with the text visualizer (the magnifying glass icon when you hover your mouse over a text variable while debugging) you will see what you expect, or what is "stored".

    In other words, Visual Studio is adding the escape sequences when it displays the text in the watch window et al; but, that's not what is stored.



  • datamathfish

    Thanks for your help - spot the VB coder who's new to C#!!

    There is so much to learn (language aside) when moving across, debugging, escaping chars (I found out about the @ symbol thing), the whole bin\debug thing - I had a file in the project explorer and it confused the hell out of me to start with as when I ran the app in debug mode it couldn't find it - so I had to past a copy in the debug folder. Surely there must be an easier way to keep the files upto date/useable

  • Un-escaping XML?