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

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

Update the name of an XML node using XPath?

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :
Hello, I have a table in an SQL Server database which contains a column of datatype XML. I wonder if it is possible to update the name of a node in that table using an XPath expressions?
The XML file stored in this column looks something like this:
and I want to update the nodename "Misspelled" and set it to "Correct". Is this possible to do this with an XPath expression or what it is the best way to do this?
After the update I want the XML to look like this:
As you can see it is the name of the node that I want to replace and not the node value.
Any help is greatly appreciated.

View Complete Post

More Related Resource Links

How can i update treeview root node every time based on the record entries

Hi all, I will have an mdi form and with a treeview which has it's initial property as visible =false. If i select an option from menu a child form will exists i will fill some details and click on save when ever click on save i will make the root node of the treeview to some name as File[batch count:0]. Now if i select another option from menu another form will appear and if i fill it with some details and click on save i would like to change the root node name to File[batch count:1] and a child node should exists with some name

Ok, XPath expert... how to access this node??

I need to alter the "something else" attribute in the xml below. The only way the correct 'category' node can be found is by finding the right 'subCat', in this case the subcat with a subCatTypeCode equal to 'B'.<root> <category> <subCat subCatTypeCode='A' /> <features> <item id='5678' attribute='something'/> </features> </category> <category> <subCat subCatTypeCode='B' /> <features> <item id='5678' attribute='something else'/> </features> </category> </root>  If you try to do something like the below, you will end up with the FIRST 'item' node.  XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(sXML); XmlNode node = xmlDoc.SelectSingleNode("//category/subCat[@subCatTypeCode='B']").ParentNode.SelectSingleNode("//features/item[@id='5678']"); Please... how to do this?  Thanks.

determining if node contains a value using XPath

I have this document:<doc>    <float name="score">1.0</float>    <arr name="services">        <str>Fotoreport</str>        <str>Exclusive</str>    </arr></doc>I want to check if the node <arr name="services"> contains the value "Fotoreport"I now have this:XPath("arr[@name=""services""]/str[@Fotoreport]")But, that doesnt work....what is the correct XPath?

Help needed on XPath Error: System.Xml.XPath.XPathException: Expression must evaluate to a node-set.

Im trying to determine if a value already exists in an XML file. In this case I want to know if there's a node "id" with value 3. But I cant figure out how...XML:<root><data><compare><locations><id>3</id><id>5</id></locations></compare></data></root>XSL:xmldoc.SelectSingleNode("//root/data/compare/locations/id=""3""")Error:XPath Error: System.Xml.XPath.XPathException: Expression must evaluate to a node-set.

how update cdata node?

Hi from spain. how can i update a cdata node in cdata format? I gave this Dim loXMLDoc As XmlDocument = New XmlDocument loXMLDoc.Load(ConfigurationManager.AppSettings("rutabase") + "XX_paginasbase\preferencias.xml") loXMLDoc.SelectSingleNode("preferencias/formularios/emailemisor").InnerText = TextBox_emailemisor.Text.Trim loXMLDoc.SelectSingleNode("preferencias/formularios/emaildestino").InnerText = TextBox_emaildestino.Text.Trim DirectCast(loXMLDoc.SelectSingleNode("preferencias/google/maps").FirstChild, XmlCDataSection).Value = TextBox_googlemaps.Text.Trim loXMLDoc.SelectSingleNode("preferencias/google/analitics").InnerText = TextBox_googleanalitics.Text.Trim loXMLDoc.SelectSingleNode("preferencias/head/keywords").InnerText = TextBox_headkeywords.Text.Trim loXMLDoc.SelectSingleNode("preferencias/head/metas").InnerText = TextBox_headmetas.Text.Trim loXMLDoc.Save(ConfigurationManager.AppSettings("rutabase") + "XX_paginasbase\preferencias.xml") loXMLDoc = Nothing i was tryed with directcast but give error. Any solution? thanks

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

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,


Xpath query to find an Node who's attribute contains a forward slash - Going crazy


If  I have a .XML file that contains the following example:

<Socks Style ="Business/Business Casual/Casual"


When I try to use the Xpath expression below to find the element above by searching for the value contained in the Style Attribute, the expression returns null:

//Socks [@Style='Business/Business Casual/Casual'] 

I downloaded xPath virtualizer and I noticed that the expression above is adding the namespace alias when it finds the embedded forward slash contained in the value of the Style Attribute (which is of course not what I want to happen).  This is driving me up a tree!!  Isn't there a way to escape the forward slash?  I know it is the slash that is the problem because for testing purposes I substituted dashes (-) in one of the nodes' Style Attribute values and then changed the xpath expression to match and it returned the exact node.

My goal is to do some replacements on all elements with the Style attribute based on each contents but I can't even try that because of this roadblock.

Please help anyone



SQL 2008:Peer 2 Peer Replication: Update-Update Conflict on the same node


My environment is comprising of 2 SQL servers setup with P2P replication in SQL 2008, 2 Web servers connect to only one SQL server at a time and make changes to the published tables and 2 Application servers which connects to both the SQL servers all the time but they only read data.

We chose P2P since my app servers are in different locations which read data from both the SQL servers and we use it as HA solution.

Since we are changing data at only one SQL server, thought we should never get update-update conflicts but we are now on the same node.

A conflict of type 'Update-Update' was detected at peer 3 between peer 1 (incoming), transaction id 0x0000000000725ca2 and peer 1 (on disk), transaction id 0x00000000007259e9 (Source: MSSQLServer, Error number: 22815)

We are making changes only at Server A and Server B is my backup server.

I made a varchar field updated in 1 row on a table in server A then it gets replicated to Server B
then I made the same field updated for 160 rows on the same table in Server A then it gets replicated to Server B
then I reverted back the change made to the field on all 160 rows on the same table in Server A then my replication failing with Update-Update conflict.

I'm not sure whats causing this because I'm not making any change

ASP.Net Gridview Edit Update Cancel Commands

In ASP.Net 2.0, GridView Control also provides the functionality to edit and update the data retrieved from the database using CommandField template. You can cancel the action using Cancel Command of the CommandField. GridView consists of events that can be used to perform the actions like edit, update and cancel upon the Data items displayed in the ASP.Net GridView Data Control.

How to format and update GridView and DataGrid rows using JQuery

The behavior described in this question is as expected. When you set text of a cell in grid, it directly affects HTML that is going to be rendered. When you set text value of a cell, it means that you are setting innerText of the cell. The column that GridView creates for command fields (Edit, Delete and Select) are a (anchor) or button elements. So you can see what will happen if you set text value in that cell. It will wipe out those link or button controls and replace them with simple text string.

Update Vs SystemUpdate

Many of you might noticed that share point ListItem has Update() method as well as SystemUpdate().

What is the difference between these two methods and why MOSS has two different APIs for updating an ListItem

SqlCommand.ExecuteNonQuery() returns -1 when doing Insert / Update / Delete

Sometimes you end up with a return value of -1 when using the SqlClient.SqlCommand.ExecuteNonQuery method.

Why is that?

Well, the ExecuteNonQuery method is there for statements for changing data, ie. DELETE / UPDATE /INSERT, and the returned value are the number of rows affected by that statement.

When checking the documentation we can see that there are some conditions that return -1.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of

rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

>>>How to update multiple rows of gidview by one click



I want to add multiple rows of a gridview if the data for multiple fields are same.

Idea for this is that a user may search a record with some parameter e.g. Sector, plot.

For example 15 records being displayed in gridview.

There should be checkbox before every row and if user wants to update Plot and Flat No that is same for 10 rows out of 15 so he will check the rows and update.

For this a dialog box should appear asking for the parameter i.e. Plot and Flat or something else next time may be it will be City or country. Moreover, there is already an Edit button to update records, when user click it another page open for the record to be updated and whatever he wants to update, it updates.

Hope everone understand the scenario.

I don't want to disturb the already provided Edit functionality and want to provide same record to be updated.

Any idea in this regard would be appreciated.

Visual Studio closes itself by opening aspx-Page designer after Windows Update


Hey Guys,

I've a problem with my Visual Studio.

On the 13th of August 2010 i installed a Windows update on my vista sp2 pc. For this date my Visual Studio 2008 sp 1 always has closed itself by opening an aspx-page in designer view. There is no error message just closing the window. I restored a backup of my windows from the time before updating it and it helped, i could open aspx pages in the design view till the update has been installed again automatically after rebooting the pc. I can't disable windows updates, cause it's my pc at work and safety is very important. I hope you could help me out of this disaster.



Update net frame 3.5.


I use visual studio 2008 but It's only use net frame work 2.0, Can I update and use net frame work 3.5 for Visual Studio 2008 ? Please help me !


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