Solved

How to read a string using InnerXml ?

Posted on 2014-10-08
9
813 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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 …

773 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