- <?xml version="1.0" encoding="utf-8"?>
-
<root>
-
<groups>
-
<group gid="1" name="CSM">
-
<contact cid="1" />
-
<contact cid="2" />
-
<contact cid="3" />
-
<contact cid="4" />
-
</group>
-
<group gid="2" name="RISIK">
-
<contact cid="5" />
-
<contact cid="6" />
-
<contact cid="7" />
-
<contact cid="8" />
-
</group>
-
</groups>
-
<contacts>
-
<contact cid="1" name="Ahmad" phoneno="0133881830" email="a@a.com" />
-
<contact cid="2" name="Nassem" phoneno="0123881830" email="a@a.com" />
-
<contact cid="3" name="Kuryu" phoneno="0164524122" email="a@wer.com" />
-
<contact cid="4" name="Moi" phoneno="0133881830" email="a@ter.com" />
-
<contact cid="5" name="Asrul" phoneno="0133511830" email="a@ter.com" />
-
<contact cid="6" name="Aizal" phoneno="0133971830" email="a@ter.com" />
-
<contact cid="7" name="Kak Esma" phoneno="0132069600" email="a@ter.com" />
-
<contact cid="8" name="Amse" phoneno="0132069600" email="a@ter.com" />
-
</contacts>
-
</root>
Please view image above and explanation below to know what I am doing Details on application: Gsm modem application developed using Visual C# 2005 Express Edition. A winform application using C#.
In my application, the group resides in a listbox. There is also a 2 other listbox that contains Member and Non-Member respectively.
When a user click on a group for example, the member listbox will be populated with the contacts. To add members in a group, we click "<" button and the member listbox will be populated with a new name from the non-member listbox. To remove member we click on the ">" button.
We can also update the group name, by selecting the group listbox and click on the edit button. The group name will appear in the Group Name textbox. We change the name and click save. Question:- - How do I update group e.g. CSM to CXX without updating / replacing the child under it. Currently when I update the parent, the child under it vanishes or overwritten with the new entry.
- How do I add the contact in a specified group?
P/S: Probably both (Q1) and (Q2) can be summed up into one method. This is because when we update a group, the contact below it will need to be populated.
Below is the code what I have attempted. Thank you in advance. -
private void savecontactingrouping(string gid) //save contact in group
-
{
-
XmlDocument xmlfonbuk = new XmlDocument();
-
xmlfonbuk.Load("../../fonbuk.dml");
-
-
XmlNodeList groupnode = xmlfonbuk.SelectNodes("/root/groups/group[@gid=" + gid + "]");
-
-
foreach (XmlNode childnode in groupnode)
-
{
-
childnode.ParentNode.RemoveAll();
-
}
-
-
-
XmlElement Elm = xmlfonbuk.CreateElement("contact");
-
// Create its attributes
-
foreach (string Cid in grouplistbox1.Items)
-
{
-
Elm.SetAttribute("cid", Cid);
-
xmlfonbuk.SelectSingleNode("/root/groups/group[@gid=" + gid + "]").AppendChild(Elm);
-
xmlfonbuk.Save("../../fonbuk.dml");
-
}
-
}
-
-
private void editgroupdetail(string name, int gid) //edit group detail
-
{
-
XmlDocument xmlfonbuk = new XmlDocument();
-
xmlfonbuk.Load("../../fonbuk.dml");
-
-
XmlElement Elm = xmlfonbuk.CreateElement("group");
-
-
// Create its attributes
-
Elm.SetAttribute("gid", Convert.ToString(gid));
-
Elm.SetAttribute("name", name);
-
-
XmlNode oldnode = xmlfonbuk.SelectSingleNode("/root/groups/group[@gid = " + gid + "]");
-
-
oldnode.ParentNode.ReplaceChild(Elm, oldnode);
-
xmlfonbuk.Save("../../fonbuk.dml");
-
-
}
-
1 1699
Hi,
You don't need to replace any node when update.
To edit the "name" attribute of a "group" node: -
XmlNode oldnode = xmlfonbuk.SelectSingleNode("/root/groups/group[@gid = " + gid + "]");
-
oldnode.Attributes.GetNamedItem("name").Text = "CXX";
-
To add a "contact" node it should work if using CreateElement() and AppendChild().
Regards,
Dorin.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: laurie |
last post by:
Hi all,
I'm trying to help out a friend who has inherited a client with a PHP
shopping cart application. Neither of us know PHP, but I've been
muddling my way through, trying to get these old scripts working on a
new server with the most recent version of PHP. I've pretty much
taken care of all the various errors that were popping up. Most only
pointed out out non-fatal undefined or assumed variables. I've been
able to cure most of...
|
by: Alan Silver |
last post by:
Hello,
I have an ASP that takes a connection string and SQL statement in the
querystring and is supposed to return the XML representation of the
recordset to the Response stream (don't worry, this is a local page, not
one on the Internet). I had it working fine with row-returning SQL, such
as SELECT, but was trying to get it to work with non-row-returnign ones
as well (such as UPDATE and DELETE). Not only can't I get this bit to
work, I...
|
by: tym |
last post by:
HELP!!!
I'm going round the twist with this...
I have a VB6 application which is using DAO to access a database
(Please - no lectures on ADO, I know what I'm doing with DAO!!)
Ok, problem is this....
importing a large csv file (189000 lines, 7 fileds per line)
|
by: jpodesta |
last post by:
Hello-
I am fairly new to MS Access and would like to use some macros in .xls
in an Access Module. I have tried to do this on my own but failed to
make it work. I have included the xls macros and the module as well as
where I would like the macros to run. Any input on how to make this
work would be appreciated. This would automate a former 3 step process
into one process.
|
by: jpodesta |
last post by:
I would like to add the xls macros below to the module listed. I am
looking for advice as to the best way to go about this.
module
Public Function clean_pn(pn_in As Variant) As String
| |
by: DP |
last post by:
hi,
i've got a price of code, which checks to see if a film is on rent, or
available. but how can i actualyl make the cancel button do somthing?
because, the cursor gets stuck on the filmID field. this is wat i've got so
far;
Private Sub FilmID_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFilmRental", "FilmID=" & Me!) > 0 Then
Cancel = True
|
by: Matthew Warren |
last post by:
I have the following piece of code, taken from a bigger module, that
even as I was writing I _knew_ there were better ways of doing it, using
a parser or somesuch at least, but learning how wasn't as fun as coding
it... And yes alarm bells went off when I found myself typing eval(),
and I'm sure this is an 'unusual' use of for: else: . And I know it's
not very robust. As an ex cuse/planation, this is what happens when you
get an idea in...
|
by: =?ISO-8859-1?Q?Gear=F3id?= |
last post by:
Hey,
This may sound odd, but is there anyway to catch the current or just
run query from inside a trigger? Kinda like how profiler displays the
query just as you've run it, along with all the statistical data...
But I'm just looking to capture the query itself and save it in a
logging table.
I just need to save an executing query in certain circumstances (if
detected an attempted sql injection attack) for logging purposes.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |