.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

add an XML node to an existing XMLdocument

Posted By:      Posted Date: September 12, 2010    Points: 0   Category :ASP.Net
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

View Complete Post

More Related Resource Links

selecting value from non-existing node

Im using XSL to retrieve a value from XML.Label1.Text = nodeList(0).SelectSingleNode("str[@name=""website""]").InnerTextBut it might be that the node <str name="website"> does not exist for the currently selected parentnode.In that case the above line will throw an error.Is there an easy way to ignore this?So that if no value can be found, just pass an empty string "" to Label1.Text?I tried using ToString, but without luck:Label1.Text = nodeList(0).SelectSingleNode("str[@name=""website""]").InnerText

Adding a full node to an existing XML document on a by xpath specified location

I want to add a complete node to an existing XML document.So:1. get the XML document from the session2. create a new node3. pass the node and the session to a function, that adds the node on the location of the xpath4. return the new session, updated with the node in the specified locationBelow my code, which DOESNT work.I've had some other advices, but nothing seems to work. What am i doing wrong?!?!Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load    Dim doc As XmlDocument = New XmlDocument()    Dim xmldoc As XmlDocument = Session("XML") 'get XMLdocument from session    Dim locationNode As XmlNode = doc.CreateElement("location")    Dim locationAttribute As XmlAttribute = doc.CreateAttribute("id")    locationAttribute.Value = "3"    locationNode.Attributes.Append(locationAttribute)    Dim titleNode As XmlNode = doc.CreateElement("title")    titleNode.AppendChild(doc.CreateTextNode("Empire State Building"))    locationNode.AppendChild(titleNode)    doc.AppendChild(locationNode)    Dim newNode As XmlNode = doc.ImportNode(locationNode, True)    AddOrUpdateNodeInSession(Session, "//root/dat

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

Replace node contents using xmldocument




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:


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,


Getting "A domain group is missing for one or more services" error when adding new node to existing


Hey all,

Current configuration:

2-node sql 2005 cluster

windows 2003 enterprise R2 w/ sp2 x64

sql 2005 enterprise x64 SP3


In the process of adding a third node into the existing 2-node cluster, we received the

"A domain group is missing for one or more services.  To install SQL 2005 as a failover cluster, domain groups must be specified for all the clustered services bing installed. To proceed, enter the missiong domain group information." 

The existing cluster functions properly and has been running w/o problems for a long while now.  An AD Global Group was created to support the cluster back when the cluster was initially created.


I found different suggestions from people online about this issue, any where from adding registry keys to take trailing blank space from sql resource group name, but none works. 


Any ideas?


Thank you in advance for any assistance.



SQL 2005 Standard to Enterprise Edition upgrade on existing three-node cluster


Current set-up: three node cluster running Windows Server 2003 Enterprise Edition SP2 with two instances of SQL Server 2005 Standard Edition SP2.


Virtual node 1: Standard Edition, default instance, Database Engine only

Virtual node 2: Standard Edition, named instance, Database Engine, Analysis Services and Integration Services


Physical node A: Prefered node for virtual node 1

Physical node B: Failover node for both virtual node 1 and 2 (thus having two installations of Standard Edition)

Physical node C: Prefered node for virtual node 2


We started off with this set-up because there was no need for Enterprise features, and SQL 2005 supports failover clustering with two nodes in Standard Edition. Saved a bundle of cash, so everybody's happy. Now we need to run a solution on virtual node 2 that requires Enterprise features in Analysis and Integration Services, so an edition upgrade is required on virtual node 2. I have done some research and found several edition upgrade examples, but none that match the above scenario. We are running production on these machines, so I can't risk experimenting with command line options, I have to be right the first time.


Is it possible to mix two editions of SQL Server 2005 in one cluster? Can I upgrade virtual node 2 to Enterprise but leave virtual node 1 at

adding a node to existing SQL Server 2000 cluster


We have a SQL 2000 cluster pair, say node A and node B. The node B has been corrupted and now the SQL instance is running only on node A. The node B has been rebuilt from scratch and OS reinstalled.

Now, we need to add the node B to node A and they should have a SQL cluster pair. Any one can provide any steps how to add this newly built node to an existing SQL 2000 cluster.

How to check for existing node while writing in XML file ?



         I have to add a node each time the compiler passes through the following code :

         string XMLFilePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Log/log.xml").ToString();

            if (File.Exists(XMLFilePath))
                XmlTextWriter xmlWriter = new XmlTextWriter(XMLFilePath, System.Text.Encoding.UTF8);
                xmlWriter.Formatting = Formatting.Indented;
                xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                xmlWriter.WriteElementString("error", "No file input");

URL Routing and Existing HttpHandler problems


Hello everyone,

I have a problem:

I am currently using 2 features: 

1. HttpHandler

Registering the path="res.aspx" verb="*"

2. URL Routing:

Registering with this pattern: "Company/Edit/{*companyId}","~/CompanyEdit.aspx"

In my CompanyEdit.aspx page, I used httphandler res.aspx to generate some images at client.

  • res.aspx?img=1
  • res.aspx?img=3

Now the problem is here, the page is load success with companyId = "12345", but when the images was loaded at client, it loaded the CompanyEdit.aspx again and show error with wrong id.  

I have debug and find the problem that because when image's urls were generated to client with url=res.aspx?img=1, url=res.aspx?img=3, the asp.net will understand that they are Company/Edit/res.aspx?img=1, Company/Edit/res.aspx?img=3 when it maps with URL Routing pattern.

=> So the CompanyEdit.aspx was load again with wrong id (id now is "res.aspx"). 

So, do you have any ideas to solve this problem, or other design.

Thanks, and best regard

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?

XML Schemas: Take Advantage of Existing External XML Schemas with a Custom Import Framework in ASP.N


Over the years, many industry-standard XML schemas and dialects have been developed. These industry-specific schemas embrace the original purpose of XML and are extremely valuable in promoting and supporting B2B interaction. Unfortunately, the ASP.NET Web Services runtime does not allow developers to directly reference external schemas from within their XML Web Services interface (the WSDL file). This article builds an external schema framework as an extension to the ASP.NET Web Services runtime to enable you to reference external schemas within your XML Web Service interface.

Scott Short

MSDN Magazine December 2002

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"

Connect to existing sql 2005 database


Hello There,

I had successfully restored sql 2000 database to sql 2005. It works like charm

Now i am creating a database model in MVC

I follow these steps

Right click on model > ADO.NET entity data model > Generate from database > New connection (Microsoft sql server) > server name > select or enter database name

But no server name AND database name show in both drop down lists. When i mannually enter database name (which exists in sql 2005) then click on TEST CONNECTION. It gives follwoing error

"A network-related or instance-specific error while establishing a connection to sql server. the server was not found or was not accessible. verify that the instance name is correct and that sql server is configured to allow remote connections.

Kindly help me with this


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,

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