473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to change xml node property by c# code

Dear all

i Wonder how can i edit a node property (in C# not by hand :) )

i have the follwing XMl file (hibernate.cfg.xml)

[html]<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" >
<session-factory name="NHibernate.Test">
<!-- properties -->
<property name="connection.provider">NHibernate.Connection.D riverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.O racleDataClientDriver</property>
<property name="connection.connection_string">User ID=th;password=manager;Data Source=th02;Persist Security Info=False</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
<property name="use_outer_join">true</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<!-- mapping files -->
<mapping assembly="Pla.Per"/>
<mapping assembly="Int.Per"/>
<mapping assembly="Pen.Map"/>

</session-factory>
</hibernate-configuration>[/html]



i want to change dynamically the connection.connection_string string property

thanks alot

ron

NOTE: Please add code or html tags to samples. Thanks, moderator.
Mar 27 '07 #1
5 17738
dorinbogdan
839 Expert 512MB
Welcome to TheScripts TSDN...

You may use XMLDocument class.
See these links:
Manipulate XML data with XPath and XmlDocument
and
Modify XML Data by Using DOM in .NET Framework

You need to use SelectSingleNode() method and to update the InnerText property of the selected XmlNode. Then call the Save() method.

I hope to succeed. Otherwise, let us know.
Mar 27 '07 #2
OK
for note this is the code which i wrote
Expand|Select|Wrap|Line Numbers
  1. XmlDocument xmlDoc = new XmlDocument();
  2.  
  3. xmlDoc.Load("hibernate.cfg.xml");
  4.  
  5. XmlNamespaceManager nm = new XmlNamespaceManager(xmlDoc.NameTable);
  6.  
  7. nm.AddNamespace("HC", "urn:nhibernate-configuration-2.0");
  8.  
  9. XmlNode node = xmlDoc.SelectSingleNode("//HC:session-factory[@name='NHibernate.Test']/HC:Property[@name='connection.connection_string']",nm);
  10.  
  11. node.InnerText = "New Value";
  12.  
  13. xmlDoc.Save("hibernate.cfg.xml");

but i have all the time node = null that means that something in the Xpath Query is incorrect
Ron


Welcome to TheScripts TSDN...

You may use XMLDocument class.
See these links:
Manipulate XML data with XPath and XmlDocument
and
Modify XML Data by Using DOM in .NET Framework

You need to use SelectSingleNode() method and to update the InnerText property of the selected XmlNode. Then call the Save() method.

I hope to succeed. Otherwise, let us know.
Mar 27 '07 #3
dorinbogdan
839 Expert 512MB
use property, not Property, to look like this:
Expand|Select|Wrap|Line Numbers
  1. xmlDoc.SelectSingleNode("//HC:session-factory[@name='NHibernate.Test']/HC:property[@name='connection.connection_string']",nm);
  2.  
Mar 27 '07 #4
Wow - you are amazing - how could i resolve this problem????!?!!? (you cant debug Xpath)
i will recommand you to be an XML MVP :)


use property, not Property, to look like this:
Expand|Select|Wrap|Line Numbers
  1. xmlDoc.SelectSingleNode("//HC:session-factory[@name='NHibernate.Test']/HC:property[@name='connection.connection_string']",nm);
  2.  
Mar 27 '07 #5
dorinbogdan
839 Expert 512MB
Thanks,
You're welcome.
God bless you.
Dorin.
Mar 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alex Sab | last post by:
Hi, I am having trouble describing in a schema that elements can be mandatory in one part and not mandatory in another part of the xml document. Here is a sample xml file <Model:Templates>...
1
by: Mr. x | last post by:
Hello, Suppose I have a table like this : <table width = "580"> <tr align = "right" width = 760> <td id = "current_page_inner"> <font size="4" color="lightgreen" face="arial"><b><i> abc...
4
by: Richard Trahan | last post by:
(This is a repost -- the original got tucked away into an old thread because I used the same Subject name.) I'm trying to change the document title to add an asterisk when the document becomes...
7
by: Keith Smith | last post by:
How can I change the background IMAGE (not just color) of a CELL in a table? I know that I can do this using CSS, but I really need to be able to do it using JavaScript. Anyone know how? Must...
2
by: kevin | last post by:
I would like to remember the state of the nodes after the treeview gets disposed, but not necessarily after the app terminates so I don't need a disk file. I was thinking about using the tag...
0
by: XML newbie: Urgent pls help! | last post by:
HI, I am working on VB.Net.My program connects to the remote host, once the login values are verified, it sends the SessionID. My problem is Although in "Logindom" variable( in the Auto window),...
0
by: Kavitha Sudhershan | last post by:
hi, i wanna read the node values from xml. As per my code i can read the node values in first child node and for the next node am not able to read the node values. pls help me. i'll paste the code...
0
by: Guzeppi | last post by:
Hi, i'm using linq to load an xml structure into my classes. the xml consists of the same node nested for multiple levels e.g. <node id="node_id01" name="node 01"> <node id="node_id0101"...
2
by: =?Utf-8?B?bWFib25k?= | last post by:
I'm using a treeview control. One parent node, several child nodes, several grandchild nodes. Each of the nodes has a checkbox. My question, when the user changes the check value of one of the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.