473,770 Members | 3,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update/Delete/Insert data from XML

Hi all,

I've been though many posts in this group and have yet to find one that
helps me understand how to accomplish my goal.

I have an XML document that stores user specific values that I need to
maintain based on options they select in a web app. Here's the XML:

<?xml version="1.0" encoding="utf-8" ?>
<MyConfig>
<UserInfo>
<UserName>Joe Schmoe</UserName>
<ReportAttribut es>
<ReqdFields>
<Field Name="Address"/>
<Field Name="City" />
<Field Name="Close_Dat e" />
<Field Name="FName1" />
<Field Name="FName2" />
<Field Name="Project" />
<Field Name="State" />
<Field Name="Zip" />
</ReqdFields>
</ReportAttribute s>
</UserInfo>
</MyConfig>

A form in the web app displays all available fields that the user can select
as a valid 'ReqdFields' option or remove them from teh list as well. How
can I update the XML and remove or add the updated fields via .NET code to
reflect the changes??

TIA
-Rich
Nov 12 '05 #1
3 8203
Here's a little progress, I just need the touchdown hint!!

-------------------------Begin Code-------------------------

Dim xmlConfig As New XmlDocument
xmlConfig.Load( "http://localhost/myapp/Config.xml")

Dim nodeList As XmlNodeList =
xmlConfig.Selec tNodes("//myappInfo/UserName")
Dim node As XmlNode
Dim listItem As ListItem

For Each node In nodeList
If node.InnerXml = Me.ddlDivision. SelectedItem.Te xt Then
node.Attributes .RemoveAll() 'Remove current attributes of
selected user and re-populate
For Each listItem In Me.listSelected .Items
Dim newElem As XmlElement =
xmlConfig.Creat eElement("Field ")
Dim newAttrib As XmlAttribute =
xmlConfig.Creat eAttribute("Nam e")
newAttrib.Value = listItem.Text
newElem.Attribu tes.Append(newA ttrib)
xmlConfig.Docum entElement.Appe ndChild(newElem )
Next
End If
Next

-------------------------EndCode-------------------------

Here's the end result:
<myappConfig>
<UserInfo>
<DivisionName>N orthern California</DivisionName>
<DivisionCode>S J</DivisionCode>
<ReportAttribut es>
<ReqdFields/>
</ReportAttribute s>
</UserInfo>
<UserInfo>
<DivisionName>T ampa</DivisionName>
<DivisionCode>T F</DivisionCode>
<ReportAttribut es>
<ReqdFields/>
</ReportAttribute s>
</UserInfo>
<Field Name="Project"/>
<Field Name="Builder"/>
</myappConfig>

So...now that I'm able to add the new elements "Field" and attributes
"Name", how can I get this data into the correct ReqdFields node based on
the selected DivisionName in the app??

TIA
-Rich

"Rich Wallace" <ri**********@m inusthecannedme at.jfsheadotcom > wrote in
message news:eP******** *****@TK2MSFTNG P11.phx.gbl...
Hi all,

I've been though many posts in this group and have yet to find one that
helps me understand how to accomplish my goal.

I have an XML document that stores user specific values that I need to
maintain based on options they select in a web app. Here's the XML:

<?xml version="1.0" encoding="utf-8" ?>
<MyConfig>
<UserInfo>
<UserName>Joe Schmoe</UserName>
<ReportAttribut es>
<ReqdFields>
<Field Name="Address"/>
<Field Name="City" />
<Field Name="Close_Dat e" />
<Field Name="FName1" />
<Field Name="FName2" />
<Field Name="Project" />
<Field Name="State" />
<Field Name="Zip" />
</ReqdFields>
</ReportAttribute s>
</UserInfo>
</MyConfig>

A form in the web app displays all available fields that the user can select as a valid 'ReqdFields' option or remove them from teh list as well. How
can I update the XML and remove or add the updated fields via .NET code to
reflect the changes??

TIA
-Rich

Nov 12 '05 #2
Help!

"Rich Wallace" <ri**********@m inusthecannedme at.jfsheadotcom > wrote in
message news:eC******** ********@TK2MSF TNGP09.phx.gbl. ..
Here's a little progress, I just need the touchdown hint!!

-------------------------Begin Code-------------------------

Dim xmlConfig As New XmlDocument
xmlConfig.Load( "http://localhost/myapp/Config.xml")

Dim nodeList As XmlNodeList =
xmlConfig.Selec tNodes("//myappInfo/UserName")
Dim node As XmlNode
Dim listItem As ListItem

For Each node In nodeList
If node.InnerXml = Me.ddlDivision. SelectedItem.Te xt Then
node.Attributes .RemoveAll() 'Remove current attributes of
selected user and re-populate
For Each listItem In Me.listSelected .Items
Dim newElem As XmlElement =
xmlConfig.Creat eElement("Field ")
Dim newAttrib As XmlAttribute =
xmlConfig.Creat eAttribute("Nam e")
newAttrib.Value = listItem.Text
newElem.Attribu tes.Append(newA ttrib)
xmlConfig.Docum entElement.Appe ndChild(newElem )
Next
End If
Next

-------------------------EndCode-------------------------

Here's the end result:
<myappConfig>
<UserInfo>
<DivisionName>N orthern California</DivisionName>
<DivisionCode>S J</DivisionCode>
<ReportAttribut es>
<ReqdFields/>
</ReportAttribute s>
</UserInfo>
<UserInfo>
<DivisionName>T ampa</DivisionName>
<DivisionCode>T F</DivisionCode>
<ReportAttribut es>
<ReqdFields/>
</ReportAttribute s>
</UserInfo>
<Field Name="Project"/>
<Field Name="Builder"/>
</myappConfig>

So...now that I'm able to add the new elements "Field" and attributes
"Name", how can I get this data into the correct ReqdFields node based on
the selected DivisionName in the app??

TIA
-Rich

"Rich Wallace" <ri**********@m inusthecannedme at.jfsheadotcom > wrote in
message news:eP******** *****@TK2MSFTNG P11.phx.gbl...
Hi all,

I've been though many posts in this group and have yet to find one that
helps me understand how to accomplish my goal.

I have an XML document that stores user specific values that I need to
maintain based on options they select in a web app. Here's the XML:

<?xml version="1.0" encoding="utf-8" ?>
<MyConfig>
<UserInfo>
<UserName>Joe Schmoe</UserName>
<ReportAttribut es>
<ReqdFields>
<Field Name="Address"/>
<Field Name="City" />
<Field Name="Close_Dat e" />
<Field Name="FName1" />
<Field Name="FName2" />
<Field Name="Project" />
<Field Name="State" />
<Field Name="Zip" />
</ReqdFields>
</ReportAttribute s>
</UserInfo>
</MyConfig>

A form in the web app displays all available fields that the user can

select
as a valid 'ReqdFields' option or remove them from teh list as well. How can I update the XML and remove or add the updated fields via .NET code to reflect the changes??

TIA
-Rich


Nov 12 '05 #3
"Rich Wallace" <ri**********@m inusthecannedme at.jfsheadotcom > wrote in message news:<OV******* *******@TK2MSFT NGP14.phx.gbl>. ..
Help!
Dim xmlConfig As New XmlDocument
xmlConfig.Load( "http://localhost/myapp/Config.xml")

Dim nodeList As XmlNodeList =
xmlConfig.Selec tNodes("//myappInfo/UserName")
Dim node As XmlNode
Dim listItem As ListItem
<myappConfig>
<UserInfo>
<DivisionName>N orthern California</DivisionName>
<DivisionCode>S J</DivisionCode>
<ReportAttribut es>
<ReqdFields/>
</ReportAttribute s>
</UserInfo>
<UserInfo>
<DivisionName>T ampa</DivisionName>
<DivisionCode>T F</DivisionCode>
<ReportAttribut es>
<ReqdFields/>
</ReportAttribute s>
</UserInfo>
<Field Name="Project"/>
<Field Name="Builder"/>
</myappConfig>
You need to go one deeper in your select nodes so you end up at the
right division (if I am reading your question correctly): Like this:
xmlConfig.Selec tNodes("//myappInfo/UserName")


Should be

xmlConfig.Selec tNodes("//myappinfo/UserName[DivisionName = 'Tampa']"

That will get you only the Tampa nodes, just replace Tampa with your
variable and you are homne free.

_Randal
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3681
by: Google Mike | last post by:
I have one table of new records (tableA) that may already exist in tableB. I want to insert these records into tableB with insert if they don't already exist, or update any existing ones with new data if they do already exist. A column (Action) in tableA already tells me whether this is an INSERT, UPDATE, or DELETE. I'm able to derive that I can do an insert with select * into tableB from tableA where Action = 'INSERT' ....and I think...
16
17018
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
16
3876
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the table, or perhaps bytes, being updated where the engine just decides, screw it, i'll just make a new one. surfed this group and google, but couldn't find anything. the context: we have some java folk who like to parametize/
25
4073
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
3
3451
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
4
2149
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft SQL database "pubs". I've followed the instructions in the comments and also changed everything pertaining to SQL over to OLEDB. (i.e. Changed SqlDbType. to OleDbType.) I also changed the datafield names and variable names accordingly. The page...
20
18385
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've been doing something like delete from foo where name = 'xx'; insert into foo values('xx',1,2,...);
5
2177
by: explode | last post by:
I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String) that creates a new oledbDataAdapter with insert update select and delete commads. I also added that commands can change depending how many columns are in a Table. I add a new column with this code: Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try...
13
1888
by: =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post by:
I am using VS2005. I created a Windows Appication project. Inside the Server Explorer, I created a new SQLExpress database, and then created a new table. I added the rows, making my first row an integer, and setting the identity property to true. I set that row to be my primary key. I then added a dataset, and added my table to the dataset. When I configure the table, I have no Update or Delete commands, even though the wizard has the...
2
2637
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
9591
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, 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...
0
9425
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,...
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10057
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9869
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 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...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
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...

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.