?
Solved

How to read a string using InnerXml ?

Posted on 2014-10-08
9
Medium Priority
?
994 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 35

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 34

Accepted Solution

by:
it_saige earned 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

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 34

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 34

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 34

Expert Comment

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

-saige-
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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!
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

762 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