Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 10th, 2009, 02:08 AM
Authorized User
 
Join Date: Apr 2007
Location: Delhi, Delhi, India.
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>
  #2 (permalink)  
Old February 14th, 2009, 12:11 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

look up DOM and xpath in c#.
  #3 (permalink)  
Old February 16th, 2009, 08:57 AM
Friend of Wrox
Points: 533, Level: 8
Points: 533, Level: 8 Points: 533, Level: 8 Points: 533, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
  #4 (permalink)  
Old February 16th, 2009, 11:52 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
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..
  #5 (permalink)  
Old February 19th, 2009, 09:02 AM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
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.
  #6 (permalink)  
Old February 19th, 2009, 09:12 AM
Friend of Wrox
Points: 533, Level: 8
Points: 533, Level: 8 Points: 533, Level: 8 Points: 533, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
  #7 (permalink)  
Old February 19th, 2009, 09:36 AM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
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..
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.