473,466 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Embedd XML within XML - Possible ??

Hi

I need to store some configuration settings in a db
using an 2 fileds

ID Field and String Field

The ID Field is a unique key and the string holds a xml string that store my
settings
Now I need to modify my configuration xml to store another parameter which
is a xml document itself. I could probably store a key in the xml to point
to the 2nd XML document but I was wondering is there a way to embed an
xml string within another xml string as an attribute within an element???

Thanks

Oct 15 '08 #1
3 1872
Hi sippyuconn,

From your description, I understand that you want to store some XML format
data via the AppSettings <itemin .net application's configuration file,
correct?

Based on my experience, it is not quite recommended that we store such
complex format text in the appsettings. this is because AppSettings <item>
use attribute to hold item value, which is designed to store some simple
text values.

If you do want to store complex XML data into the attribute field. I think
you can consider the following means:

1. First, your xml data have to be encoded into a safe format(which won't
violate the container xml document). One simple means is using HtmlEncode
to encode the embeded xml(which is to put into appsetting item).

2. When you read the item out, you need to HtmlDecode it.

Here are two simple functions demonstrate this:

=============================
static void StoreXML()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(@"<root><items>
<item id ='1'></item><item id='2'></item>
</items>
</root>
");

Configuration config
=ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None);

doc.PreserveWhitespace = false;
StringWriter sw = new StringWriter();
doc.Save(sw);

config.AppSettings.Settings["doc1"].Value = null;
config.AppSettings.Settings["doc1"].Value =
HttpUtility.HtmlEncode(sw.ToString());

config.Save();

}

static void ReadXML()
{
string rawdoc = ConfigurationManager.AppSettings["doc1"];

XmlDocument doc = new XmlDocument();

string xml = HttpUtility.HtmlDecode(rawdoc);

doc.LoadXml(xml);

Console.WriteLine(doc.OuterXml);

}
=========================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: =?Utf-8?B?c2lwcHl1Y29ubg==?= <si********@newsgroup.nospam>
Subject: Embedd XML within XML - Possible ??
Date: Tue, 14 Oct 2008 18:46:00 -0700
>
Hi

I need to store some configuration settings in a db
using an 2 fileds

ID Field and String Field

The ID Field is a unique key and the string holds a xml string that store
my
>settings
Now I need to modify my configuration xml to store another parameter which
is a xml document itself. I could probably store a key in the xml to point
to the 2nd XML document but I was wondering is there a way to embed an
xml string within another xml string as an attribute within an element???

Thanks

Oct 15 '08 #2

If you're doing this so you can store "complex" information in your
app.config or web.config, this is a hack.

...

A better solution would be to author your own configuration section
"Handler" (and "Settings") class.

I have a working example here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry

Ignore the SMTP stuff, just focus on the
EmailSmtpSettingsHandler : IConfigurationSectionHandler
class...and how I parse the xml to create a strong object.
Or go here:
http://msdn.microsoft.com/en-us/library/2tw134k3.aspx
or here
http://support.microsoft.com/default...b;en-us;309045
But "xml inside an xml" doesn't have a good feel to it, IMHO.


"sippyuconn" <si********@newsgroup.nospamwrote in message
news:37**********************************@microsof t.com...
Hi

I need to store some configuration settings in a db
using an 2 fileds

ID Field and String Field

The ID Field is a unique key and the string holds a xml string that store
my
settings
Now I need to modify my configuration xml to store another parameter which
is a xml document itself. I could probably store a key in the xml to point
to the 2nd XML document but I was wondering is there a way to embed an
xml string within another xml string as an attribute within an element???

Thanks

Oct 15 '08 #3
Hi Sippy,

Have you got any progress on this issue or does the suggestion in my last
reply help you some? If there is anything else we can help, please feel
free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

--------------------
>From: =?Utf-8?B?c2lwcHl1Y29ubg==?= <si********@newsgroup.nospam>
Subject: Embedd XML within XML - Possible ??
Date: Tue, 14 Oct 2008 18:46:00 -0700
>Hi

I need to store some configuration settings in a db
using an 2 fileds

ID Field and String Field

The ID Field is a unique key and the string holds a xml string that store
my
>settings
Now I need to modify my configuration xml to store another parameter which
is a xml document itself. I could probably store a key in the xml to point
to the 2nd XML document but I was wondering is there a way to embed an
xml string within another xml string as an attribute within an element???

Thanks

Oct 20 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mh | last post by:
Hi everybod who knows the *.dll to embedd the command prompt into C#, what i want to do, is make a graphical command prompt based on System.Windows.Forms Thanks for helping
0
by: Nuno Magalhaes | last post by:
How do I embedd the MediaPlayer (msdxm.ocx) in a Windows Form using C#? I do something like the code below: Player=new WindowsMediaPlayer();...
1
by: Nuno Magalhaes | last post by:
How do I embedd an ocx control in a windows form in C#? Does it inherit from Microsoft.Windows.Forms.Form? Thanks for any response to this newbie question, Nuno Magalhaes.
1
by: Anamika | last post by:
I am trying to embedd Ms Word object in asp.net application and retrieve from & save back to database. Anybody done this before ? I would appreciate if anybody send some sample code. TIA.
1
by: Mike TI | last post by:
April 18, 2006 Hi all I have built a small application in VB Net 2005 that uses SQL Express 2005. Now I want to create a 'Setup Procedure' that should install the application as well as SQL...
3
by: Siv | last post by:
Hi, A little while ago I wrote a small program that allowed the user to view products from a database. The database holds the details of the products which can be viewed via a form and...
1
by: Joe | last post by:
Hi I am trying to build a XML db and within this I want to store an XML string as 1 element as "Info" below If I build up a XMLDocument with data - how can I transform it to a string...
0
by: Preeti | last post by:
Hi All I am new to WPF. I need to embedd a flash video on a WPF screen. But I think mediaelement does not support that. Can anyone tell me what do I need to be able to embedd a flv video on a...
6
by: ankitkhare | last post by:
Hi, I have this javascript which i am trying to embedd in my C# code,i am not sure whether it is even possible or not! If it is possible then how can i do it?Any document or links will be...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.