Solved

How to read a string using InnerXml ?

Posted on 2014-10-08
9
787 Views
Last Modified: 2014-10-08
I am using following code to read a string from XML file. I have to read
a following  string from the XML file. How to read this string ?  "mcQKhSSzcMP9199vA8Bod1/y6VJrZNL3m4AQiDHwonHyuSUctBQY/cgOz5rakHa2d5mVKSSxdE2RjDDB0DxKUsoWbddaeej6ufY6fUj6ACmwJQyiB+I3OA=="



c# code:
  XmlDataDocument doc = new XmlDataDocument();
            doc.Load(@"C:\Temp\Connection.exe.config");
           
            
            XmlElement root = doc.DocumentElement;
     XmlNodeList elemList = root.GetElementsByTagName("connectionStrings");

Open in new window




XML File:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
      <clear/>
      <add name="Encrypted"
             providerName="System.Data.SqlClient"
             connectionString="mcQKhSSzcMP9199vA8Bod1/y6VJrZNL3m4AQiDHwonHyuSUctBQY/cgOz5rakHa2d5mVKSSxdE2RjDDB0DxKUsoWbddaeej6ufY6fUj6ACmwJQyiB+I3OA=="
		/>
    </connectionStrings>
    </configuration>

Open in new window

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
      <clear/>
      <add name="Encrypted"
             providerName="System.Data.SqlClient"
             connectionString="mcQKhSSzcMP9199vA8Bod1/y6VJrZNL3m4AQiDHwonHyuSUctBQY/cgOz5rakHa2d5mVKSSxdE2RjDDB0DxKUsoWbddaeej6ufY6fUj6ACmwJQyiB+I3OA=="
		/>
    </connectionStrings>
    </configuration>

Open in new window

0
Comment
Question by:Varshini S
  • 4
  • 3
  • 2
9 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 40368342
Don't access your config files manually. Use the ConfigManager class instead.
0
 

Author Comment

by:Varshini S
ID: 40368372
ste5an: You are absolutely correct. But for this scenario  I need to read manually.
0
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40368450
The following example shows how to read the attributes of the innerXml:
using System;
using System.Xml;

namespace XmlExample
{
	class Program
	{
		static void Main(string[] args)
		{
			XmlDataDocument doc = new XmlDataDocument();
			doc.Load("Connection.exe.config");

			XmlElement root = doc.DocumentElement;
			XmlNodeList elemList = root.GetElementsByTagName("connectionStrings");
			foreach (XmlNode item in elemList)
			{
				Console.WriteLine(string.Format("Root Node - {0}; contains {1}",item.Name ,item.InnerXml));
				if (item.HasChildNodes)
				{
					foreach (XmlNode child in item.ChildNodes)
					{
						Console.WriteLine(string.Format("Child Node - {0} of Parent Node - {1}; contains {2}", child.Name, child.ParentNode.Name, child.InnerXml));
						if (child.Attributes.Count > 0)
						{
							Console.WriteLine(string.Format("Child Node - {0} contains attributes.", child.Name));
							foreach (XmlAttribute attribute in child.Attributes)
								Console.WriteLine(string.Format("Attribute {0} of Child Node - {1}; contains {2}", attribute.Name, child.Name, attribute.InnerXml));
						}
					}
				}
			}
			Console.ReadLine();
		}
	}
}

Open in new window


Produces this output:Capture.JPG
-saige-
0
 
LVL 33

Expert Comment

by:ste5an
ID: 40368555
You are alreading reading your string. But I guess you want to decrypt this string.

Normally you would use an Protected Configuration Provider.

The problem is quite simple: I don't recognize this encryption schema...

So hard to tell. How was this config file generated?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Expert Comment

by:it_saige
ID: 40368574
@ste5an - Offhand it looks like an encoded public or private key generated using the RSACryptoServiceProvider.

-saige-
0
 

Author Comment

by:Varshini S
ID: 40368713
ste5an - Application configuration file sitting in outside my application and more than 5 application sharing the same config file. So I have used TripleDES  encryption and generated the keys. During the run time I will decrypt the connection string.
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40368729
@Varshini - Have you looked at the code I provided to see if that leads you down the right path?  If needed I could provide more information.

-saige-
0
 

Author Comment

by:Varshini S
ID: 40368738
Saige- Thank You. This works for me
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40369247
Don't forget to accept the solution.

-saige-
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now