Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2009, 02:08 AM
Authorized User
 
Join Date: Apr 2007
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update the node value of XML file

Hello Friends,

I've a XML file as shown below i want to update the path of the flv files which i've made bold below. Actually i've a playlist and my video player takes the properties from this XML file so i've to play the different different video which i click on.


<CONFIG>

<SETTINGS>
<PLAYER_SETTINGS Name="SelectedSkin" Value="../Files/Skins/flvplayer/skin.swf"/>
<PLAYER_SETTINGS Name="SelectedLoader" Value="../Files/Skins/flvplayer/loading.swf"/>

<PLAYER_SETTINGS Name="FLVPath" Value="http://localhost:4718/VideosUploading/Files/Videos/2.flv"/>

</SETTINGS>
</CONIG>
 
Old February 14th, 2009, 12:11 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

look up DOM and xpath in c#.
 
Old February 16th, 2009, 08:57 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

Forget DOM and xpath that's old school. Use LINQ. Just use something like this.

Code:
XDocument xml = XDocument.Load(@"C:\XMLFile1.xml");
            var query = from p in xml.Elements("CONFIG").Elements("SETTINGS").Elements("PLAYER_SETTINGS")
                        where (string)p.Attribute("Name") == "FLVPath"
                        // and ....
                        select p;

            foreach (var record in query)
            {
                record.SetAttributeValue("Value", "new path");
            }
Cheers, John Bampton.
 
Old February 16th, 2009, 11:52 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

To be honest, this is simply ugly. If you really into LINQ, then write this in LINQ to XSD instead of LINQ to XML.

Between XQuery and LINQ to XSD, they are too close to be compared just based on the face value. With .Net, LINQ obviously provides some consistancy between different types of objects being queried against.

Last edited by PeterPeiGuo; February 17th, 2009 at 12:29 AM..
 
Old February 19th, 2009, 09:02 AM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

I was porbably ahead of myself with LINQ to XSD, not sure whether it's part of VS2008 and .Net 3.5.
 
Old February 19th, 2009, 09:12 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

I gave the solution and you bashed it. you were wrong
 
Old February 19th, 2009, 09:36 AM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

It had nothing to do with your solution. LINQ to XML is not type safe when compared to LINQ to XSD, and I don't believe you can argure that. Perl is ugly, but many have written beautiful code in it, see what I mean?

Last edited by PeterPeiGuo; February 19th, 2009 at 10:01 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
append a xml node from one file to another pravind XSLT 5 August 22nd, 2009 09:15 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Force SQL to update the data from an xml file ivanv SQL Server 2005 0 April 23rd, 2007 04:07 AM
how to update a xml file billbillbill XML 2 April 11th, 2007 08:23 AM
update xml file using vbs thesun99 XML 0 March 21st, 2005 02:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.