473,396 Members | 1,832 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,396 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 17740
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.