Groups | Blog | Home
all groups > dotnet xml > september 2004 >

dotnet xml : Update/Delete/Insert data from XML


Rich Wallace
9/8/2004 1:52:29 PM
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>
<ReportAttributes>
<ReqdFields>
<Field Name="Address"/>
<Field Name="City" />
<Field Name="Close_Date" />
<Field Name="FName1" />
<Field Name="FName2" />
<Field Name="Project" />
<Field Name="State" />
<Field Name="Zip" />
</ReqdFields>
</ReportAttributes>
</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

Rich Wallace
9/9/2004 8:06:10 AM
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.SelectNodes("//myappInfo/UserName")
Dim node As XmlNode
Dim listItem As ListItem

For Each node In nodeList
If node.InnerXml = Me.ddlDivision.SelectedItem.Text 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.CreateElement("Field")
Dim newAttrib As XmlAttribute =
xmlConfig.CreateAttribute("Name")
newAttrib.Value = listItem.Text
newElem.Attributes.Append(newAttrib)
xmlConfig.DocumentElement.AppendChild(newElem)
Next
End If
Next

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

Here's the end result:
<myappConfig>
<UserInfo>
<DivisionName>Northern California</DivisionName>
<DivisionCode>SJ</DivisionCode>
<ReportAttributes>
<ReqdFields/>
</ReportAttributes>
</UserInfo>
<UserInfo>
<DivisionName>Tampa</DivisionName>
<DivisionCode>TF</DivisionCode>
<ReportAttributes>
<ReqdFields/>
</ReportAttributes>
</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" <rich.wallace@minusthecannedmeat.jfsheadotcom> wrote in
message news:eP0oFXelEHA.324@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

Rich Wallace
9/9/2004 5:00:48 PM
Help!

"Rich Wallace" <rich.wallace@minusthecannedmeat.jfsheadotcom> wrote in
message news:eCz%23L6nlEHA.3608@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

frandalc NO[at]SPAM swbell.net
9/10/2004 10:01:48 AM
[quoted text, click to view]

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:

[quoted text, click to view]

Should be

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

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

AddThis Social Bookmark Button