.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Replace node contents using xmldocument

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net



Attempting to replace the contents of a node, but not having much luck..

I need to look at my Keywords node, if it has the word 'test,' in it then replace it with ""

Essentially I'm trying to delete one of the keywords - they will always have a comma after each word as well.

So I'm trying to say in code: For any elements that is in the department Claims, get the Keywords & if it contains the string 'test,' replace it with nothing.


My elements look like this:

    <Link Type="Page" Target=""><![CDATA[]]></Link>

..additional elements just like this one..


My code like this:


View Complete Post

More Related Resource Links

Treeview - how to change node icon depending on node contents

I have a treeview in an MVVM application: <TreeView ItemsSource="{Binding RootNodes}"> <TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /> <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /> <Setter Property="FontWeight" Value="Normal" /> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="FontWeight" Value="Bold" /> </Trigger> </Style.Triggers> </Style> </TreeView.ItemContainerStyle> <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Children}"> <TextBlock Text="{Binding NodeName}" /> </HierarchicalDataTemplate> </TreeView.ItemTemplate> </TreeView> The treeview is bound to an ObservableCollection called RootNodes. Elements in the RootNodes collection expose a member "NodeName" which is the text for the nodes in the treeview at runtime. They also expose a member called "NodeType", effectively an enumeration that indicates what type of icon should be displa

add an XML node to an existing XMLdocument

I want to add an XML node (locationNode) to an existing XMLdocument (xmldoc)However, I get the error: The node to be inserted is from a different document context.Which makes sense, but then I dont know how I can do what I want.Here's my code:Dim doc As XmlDocument = New XmlDocument()Dim locationNode As XmlNode = doc.CreateElement("location")Dim locationAttribute As XmlAttribute = doc.CreateAttribute("id")locationAttribute.Value = "3"locationNode.Attributes.Append(locationAttribute)'doc.AppendChild(locationNode)Dim titleNode As XmlNode = doc.CreateElement("title")titleNode.AppendChild(doc.CreateTextNode("Opera house"))locationNode.AppendChild(titleNode)xmldoc.AppendChild(locationNode)contents of xmldoc:    <root>    <data>        <compare>            <locations>                <location id="4">                    <title>Empire state building</title>                </location>                <location id=&quo

XMLDocument, problem reading Node.




I am doing the following:


System.Net.WebRequest myRequest = System.Net.WebRequest.Create("http://www.atlantawithkid.com/feed/"); 
System.Net.WebResponse myResponse = myRequest.GetResponse(); 
System.IO.Stream rssStream = myResponse.GetResponseStream(); 
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument(); 
System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); 
System.Xml.XmlNode rssDetail; 
string sRssDescription;  
rssDetail = rssItems.Item(0).SelectSingleNode("description"); 
if (rssDetail != null) 
    sRssDescription = rssDetail.InnerText; 

However, when I read the "description" node and view the InnerText, or the InnerXML, the string is different than in the original XML document.

The string returned has and ellipses and the data is truncated. However, in the original XML document there is data that I can see.

Is there a way to select this node without the data being altered?

The original XML <description> node is as follows:

			<description xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="html">
				<div class="tweetmeme_button" style="float:right;margin-le

How to get node using XMLDocument and update value



This is my XML.

<xml version="1.0" encoding="utf-16">
    <x> test value 1 </x>
    <y> test value 2</y>

        <x> test value 3</x>
        <y> test value 4</y>

                <x> test value 5</x>
                <y> test value 6 </y>




The actual XML is a deep hierarchy same way above that has so may <objA> and <objB>.

Please remember, I have to use XMLDocument only, not XDocument.

Now, I have to find a particular <objA> where <x> = "test value 5" and update its <y> to "some new value".

and then save that whole XMLDocument so that it is updated.

Can someone please tell me how can I achieve this using XMLDocument?


Thanks in advance,


Can I replace the EntityObject as base-class in Entity Designer 3.5 sp1?


I'm using EF3.5sp1 for a project, and I've been working around many of its problems... as such, my entity partial classes have a lot of logic in them for change-tracking and whatnot.  Obviously, I'd like to factor this logic out into a common base class, but of course all my objects must derive from EntityObject.  Is it possible to tell them to derive from some class of my own invention (which would actually likely derive from EntityObject themselves)?

I'd rather avoid editing the EDMX file unless the changes will be safe on entity-model-update, since I'm still making changes to the database schema in this early state of my project.


Also, is there any good workaround for the fact that the change isn't tracked when you change EntityReference.EntityKey?

Display homepage node along with child nodes


If the first Sitemap node is your homepage/default and all other nodes are supposed to be children / grandchildren of the first sitemap node in a web.sitemap, how do I set up my web.sitemap to enable me to display my cssFriendlyMenu with the homepage node along with the nodes that are 1 level down from it at the same time as in :

Home   Products   Services   About us


...or is it not possible to have the first sitemap node displayed along with the nodes that are 1 level down from it?  Do I need to have a different starting node rather than my homepage node?

ImageURL SiteMap Node


Hi Can anyone tell me how i can add the ImageURL from a sitemap into a navigation menu, i had this working with webforms but cannot get it to work with mcv

var sbMenuHelper = new StringBuilder();

sbMenuHelper.Append("<ul class='cssMenu'>");

var topLevelNodes = SiteMap.RootNode.ChildNodes;
foreach (SiteMapNode node in topLevelNodes)
    if (SiteMap.CurrentNode == node)
        sbMenuHelper.AppendFormat("<a href='{0}'>{1}</a>", node.Url, helper.Encode(node.Title));

return sbMenuHelper.ToString();

        description="Contact Us"

Addressing a specific node with CSS Friendly Control Adapters


Hello everybody,

I like the concept of the friendly control adapters, but I'm not sure if I can use them for my purpose.
My whole menu basically consist of one image, which itself contains the images for each menu item (is that understandable?).

Each menu item then displays only a certain part of the image.
I do this by shifting the background-position.

#navigation li#home a{
background-position:0px 0px;

/* Registration */
#navigation li#registration a:link, li#registration a:visited {
background-position:-106px -34px;

#navigation li#registration a:hover, li#registration a:focus {
background-position:-106px 0px;

/* Administration */
#navigation li#administration a:link, li#administration a:visited{
background-position:-212px -34px;

#navigation li#administration a:hover, li#administration a:focus{
background-position:-212px 0px;


I would like to do the same now with CSS Friendly, but I don't see how I can address each individual menu item node.
In static HTML I can give each link an ID (i.e. #administration), but I don't see how to do this with the asp:Menu control and CSS Friendly.

Can someone help me?

Thanks a lot,

(Imperfect) Solution to TreeView Postback / Client-Side Node Selection Issue


I've seen this question posted on all corners of the web... "How do I disable "AutoPostBack" on the ASP.NET 2.0 TreeView control?!"  Unfortunately, most of the answers either don't work, miss the point (don't work right), or boil down to "You can't do it."  I happen to know that this behavior worked perfectly in the IEWebControls TreeView that Microsoft released as an add-on prior to ASP.NET 2.0, however.  So I set out to find a solution for the ASP.NET 2.0 TreeView issue.

In a nutshell, the behavior that I and others are looking for is to have a TreeView rendered in a page that allows the user to expand, contract, and select nodes within the TreeView without causing a PostBack to the server.  This implies two things: (1) the most recently-selected node should be recorded as the currently-selected node [i.e., at PostBack time, the most-recently selected node is actually represented as the SelectedNode]; and (2) the selected node should exhibit the SelectedNodeStyle as specified in the TreeView declaration.

It appears that the TreeView engineers saw only two possible outcomes from selecting a leaf node in a tree: (1) immediately posting back to the server, or (2) immediately navigating to another web page.  They apparently did not consider option (3) just allowing selection in-place on the client, while waiting for a click on so

Regex.replace [h2] to


I try to replace [h2] to <h2>
I use this coding:

string o = "<h2>test</h2>";
o = Regex.Replace(o, "[h2]", "<h2>");
o = Regex.Replace(o, "[/h2]", "</h2>");


But the result after the first regex is:


So that is not what i want.
After the first 1, he should make:


Whats wrong?

Replace text in a word document stored in a Document Library


Hi to all,

im tying to replace some text introduced in a word document stored in a document library.

Exactly i need a web part with a button that change a key in a word template <list> (for example) and replace <list> with a text in another list.


I think that it would works with the Microsoft.Office.Word.Interop; namespace but when i call the function :

wDoc = wordApp.Documents.Open(ref fileName, ref missing,
                                ref readOnly, ref missing, ref missing, ref missing,
                                ref missing, ref missing, ref missing, ref missing,
                                ref missing, ref isVisible, ref missing, ref missing,

The replace of web application stress tool

Hi i want  know in 2010 what is the replace of web application stress tool. what is the new tool for testing application , not Microsoft test manager,  with out a tema foundatin server a application like jmeter   thamks

Change case using Find & Replace dialog box

Hi, I want to change case of link URLs using Find & Replace dialog box . Is it possible? eg changing http://www.abc.com/S pecial-E dition.aspx, http://www.abc.com/O ther-N ews.aspx to http://www.abc.com/s pecial-e dition.aspx, http://www.abc.com/o ther-n ews.aspx

Find and replace link source

I want to replace links href in the source code using regular expression in Find/Replace dialog box from http://www.abc.com/car-news/13PX5S/News1.aspx, http://www.abc.com/car-news/27JXW5/News2.aspx to http://www.abc.com/car-news/news1/13px5s/, http://www.abc.com/car-news/news2/27jxw5/   - in the resultant URL there will be no Capital letters.    

XMLSerializer don't handle mixed contents properly

mixed content model allows a combination of text and elements in the XML document. we use .net xmlserializer to serialize/deserialize the XML. XmlSerializer don't handle mixed content properly. XmlSerializer handles mixed content models to a degree. XmlSerializer add the text in the xml document, but the position of text is not exactly where they appeared in the original XML document. Let's take a example here is original xml <employee xmlns="http://example.org/xmlserializer">   here is some text...   <id>333-33-3333</id>   here is some more...   <name>Bob Smith</name>   and here is even more... </employee> We deserialize above xml using the xmlserializer then we serialize it back into xml. Now xml document is changed as follows <employee xmlns="http://example.org/xmlserializer">    <id>333-33-3333</id>   <name>Bob Smith</name>   here is some text...   here is some more...    and here is even more... </employee> You see the position of text is changed. I have seen the Microsoft code to serialize/deserialize the xml through reflector. They put text in a string array but position is not saved. Is there any solution or workaround? I don't want to parse the xml by xmlReader. I want fix in the Microsoft generated classes that ar

Node probability distibution - values don't sum to 1?

Hi, I am using sequence clustering algorithm and I have checked Node probability distribution (state transition) for one of the cluster. Probability values don't sum to 1. Why? I think they should. Do I miss something?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend