Solved

How to read a string using InnerXml ?

Posted on 2014-10-08
9
753 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 32

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 32

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 32

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 32

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 32

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 32

Expert Comment

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

-saige-
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Email Body 4 47
cs.Designer Issue(2) 2 23
c# if statement weird reaction 3 30
install app on other machine 13 18
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

13 Experts available now in Live!

Get 1:1 Help Now