Load and update XML file from webpage

Rattlesnake

Well-known member
Joined
Dec 23, 2003
Messages
47
Hi ,
I have a ASP.Net 1.1 application that uses an XML file (AppConfig.xml) to read configuration parameters
The XML file looks like this

<AppParameters>
<Global>
<Parameter1 value="1000" />
<Parameter2 value="True" />
<Parameter3 value="Approve" />

</Global>
<OrderList>
<ShowCol6 value="True" />
<ShowCol7 value="False" />
<ShowCol8 value="False" />
<OrderList>

<DeliveryList>
<Parameter1 value="True" />
<Parameter2 value="True" />
<Parameter3 value="500" />
</DeliveryList>
</AppParameters>

It has multiple sections (a section for each application module). Each section has different parameters.

I want to have a ASP.net page that will LOAD and DISPLAY all theses parameters.
I want to be able to modify them and SAVE them back to the XML file

Basically what I am looking for is to recursively read an XML file that has the above structure and be able to update each Parameter.

Thanks for ur help
 
i havent done anything with xml and webpages yet, but have some experience with xml, so Im going to take a stab at the xml part only. Youll need help from someone else on the web part.

Not sure how much Xml experience you have so Im going to over-explain this.

if your x file is as above, meaning youre not nesting groups inside of groups, then all you need is an xml node list, and youre not going to need recursion.

In your file specifically, "AppParameters" is your root node. So, to select every child node to that, you say:
Code:
load xdoc, etc here
...
this part gets your root node; XML IS case sensitive!!!
Dim xn as XmlNode
xn = xDoc.selectSingleNode("//AppParameters")

this part gets the child nodes. each child will include all subnodes, 
so it will look like this:
<Global>
  <Para....
</Global>
Dim xl as XmlNodeList
xl = xDoc.ChildNodes

Now you can iterate through each node:
For each xn in xl
  do your display work here
Next xn

If you sometimes have grandchildren that are also groups, then youre going to have to use recursion, but im skipping that for now. If you do have that and run into problems, let me know.
 
Also, heres some handy XML links.

A few good, semi-short tutorials:

A quick-ref for XPath query syntax, part of the xpath tutorial above:

And finally, an extremely handy tool, jEdit. Its an open source extensible text editor, and does wonders with Xml Docs. Get it here:
http://www.jedit.org

Youll want these plug-ins at a minimum:
  • XML
    checks your xdoc for correct structure, adds text coloring, etc.
  • XQuery Plugin
    lets you run queries against xdocs and displays the outputs; a few different options for source doc and output location. Yes, Plugin is part of its name ;-)
  • SideKick
    displays your xdoc in a tree
  • Beauty
    auto-indents your document
  • BufferTabs
    adds a little more control and nice features to the buffer
Some of those have other required plugins, obviously take them as well. It will tell you on the site.

And finally, sorry if you already knew all of this and I overexplained it.
 
Last edited by a moderator:
Back
Top