-
Modify XML on the fly
Which .NET class to use to modify xml on the fly?
IE. <node address="hello">
change to <node address="world">
-
Re: Modify XML on the fly
"barknee@westrew.com" <none@none.com> wrote:
>
>Which .NET class to use to modify xml on the fly?
>
>IE. <node address="hello">
>
>change to <node address="world">
>
>
-
Re: Modify XML on the fly
Hi
See XmlDocument and XmlNode
You have to load document
XmlDocument dom = new XmlDocument ();
dom.Load ("...");
// then select node
XmlNode node = dom.SelectSingleNode("...");
node.attributes["address"].Value = "world";
// and then you could save
dom.Save(...);
Miha
"barknee@westrew.com" <none@none.com> wrote in message
news:3d32d0e5$1@10.1.10.29...
>
> Which .NET class to use to modify xml on the fly?
>
> IE. <node address="hello">
>
> change to <node address="world">
>
>
-
Re: Modify XML on the fly
"Miha Markic" <miham@pleasenospam.spin.si> wrote:
>Hi
>
>See XmlDocument and XmlNode
>
>You have to load document
>XmlDocument dom = new XmlDocument ();
>dom.Load ("...");
>// then select node
>XmlNode node = dom.SelectSingleNode("...");
>node.attributes["address"].Value = "world";
>// and then you could save
>dom.Save(...);
>
>Miha
>
>"barknee@westrew.com" <none@none.com> wrote in message
>news:3d32d0e5$1@10.1.10.29...
>>
>> Which .NET class to use to modify xml on the fly?
>>
>> IE. <node address="hello">
>>
>> change to <node address="world">
>>
>>
>
>
Thanks. I have that but now I cannot get the file to close. I need the
file to save, but apparently even thought the Document object goes out of
scope a HANDLE to the file is still open. ???
-
Re: Modify XML on the fly
If you are using XmlTextWriter, make sure you call Close() at the end.
--
Miha
www.spin.si/www/eng
"barknee@westrew.com" <cplus.@127.0.0.1> wrote in message
news:3d341c93$1@10.1.10.29...
>
> "Miha Markic" <miham@pleasenospam.spin.si> wrote:
> >Hi
> >
> >See XmlDocument and XmlNode
> >
> >You have to load document
> >XmlDocument dom = new XmlDocument ();
> >dom.Load ("...");
> >// then select node
> >XmlNode node = dom.SelectSingleNode("...");
> >node.attributes["address"].Value = "world";
> >// and then you could save
> >dom.Save(...);
> >
> >Miha
> >
> >"barknee@westrew.com" <none@none.com> wrote in message
> >news:3d32d0e5$1@10.1.10.29...
> >>
> >> Which .NET class to use to modify xml on the fly?
> >>
> >> IE. <node address="hello">
> >>
> >> change to <node address="world">
> >>
> >>
> >
> >
>
> Thanks. I have that but now I cannot get the file to close. I need the
> file to save, but apparently even thought the Document object goes out of
> scope a HANDLE to the file is still open. ???
-
Re: Modify XML on the fly
Yeah, I found it. I have an MMC snap-in that modifies web.config on the fly
and when I got done showing it, well I forgot to close it. Ooops
"Miha Markic" <miham.nospam@spamno.spin.si> wrote:
>If you are using XmlTextWriter, make sure you call Close() at the end.
>
>--
>Miha
>www.spin.si/www/eng
>
>"barknee@westrew.com" <cplus.@127.0.0.1> wrote in message
>news:3d341c93$1@10.1.10.29...
>>
>> "Miha Markic" <miham@pleasenospam.spin.si> wrote:
>> >Hi
>> >
>> >See XmlDocument and XmlNode
>> >
>> >You have to load document
>> >XmlDocument dom = new XmlDocument ();
>> >dom.Load ("...");
>> >// then select node
>> >XmlNode node = dom.SelectSingleNode("...");
>> >node.attributes["address"].Value = "world";
>> >// and then you could save
>> >dom.Save(...);
>> >
>> >Miha
>> >
>> >"barknee@westrew.com" <none@none.com> wrote in message
>> >news:3d32d0e5$1@10.1.10.29...
>> >>
>> >> Which .NET class to use to modify xml on the fly?
>> >>
>> >> IE. <node address="hello">
>> >>
>> >> change to <node address="world">
>> >>
>> >>
>> >
>> >
>>
>> Thanks. I have that but now I cannot get the file to close. I need the
>> file to save, but apparently even thought the Document object goes out
of
>> scope a HANDLE to the file is still open. ???
>
>
-
RE: Modify XML on the fly
know that you implement some code to change your web.config file. I'm trying
to do the same.
I can change it successfully, but then when I check my config file using
"ConfigSettings", he gaves back to me the old values
Seems to me that the application loads the file into memory and then, if I
want I have to reload the config file.
Can you tell me how to do this?
-
RE: Modify XML on the fly
"Nelson" <nelson.carvalho@movensis.com> wrote:
>know that you implement some code to change your web.config file. I'm trying
>to do the same.
>I can change it successfully, but then when I check my config file using
>"ConfigSettings", he gaves back to me the old values
>
>
>
>Seems to me that the application loads the file into memory and then, if
I
>want I have to reload the config file.
>
>Can you tell me how to do this?
>
Here's a sample. Place your names in as needed:
public void ModifyAttribute(string strXPath, string strKey, string strNewValue)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(@"c:\adbs\bin\web.config");
XmlNodeList nodeList = doc.SelectNodes(strXPath);
foreach (XmlNode node in nodeList)
{
string strValue = node.Name;
if(node.Attributes["key"].Value == strKey)
{
node.Attributes["value"].Value = strNewValue;
}
}
doc.Save(@"c:\adbs\bin\web.config");
}
catch(Exception ex)
{
throw ex;
}
}
public void ModifyAllAttributes(string strXPath, string strAttribute, string
strNewValue)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(@"c:\adbs\bin\web.config");
XmlNodeList nodeList = doc.SelectNodes("//ADBSSectionGroup//ADBSSoapTracing//add");
foreach (XmlNode node in nodeList)
{
node.Attributes["value"].Value = strNewValue;
}
doc.Save(@"c:\adbs\bin\web.config");
}
catch(Exception ex)
{
throw ex;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks