Ok, the part you have is definately what you want in order to pull the XML data into an object. At this point you get to learn about all kind of nifty stuff, like DOM and XPath
W3Schools has some tutorials on both:
You basically have two ways to retrieve the data that you need. You can either navigate the DOM tree of the XML by referencing child nodes or you can use XPath statements inside a SelectNodes (or SelectSingleNode) to retrieve the exact node you need from wherever it is in the document.
I prefer XPath queries, for the simple fact that I find it easier to maintain the code when I see text instead of chained .childNodes(0).childNodes(0).etc
A simple example of getting the username and password using XPath:
Code:
set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
xmldoc.load(Request)
Dim user_name, user_pass
user_name = xmldoc.SelectSingleNode("/prop/code/user@username").Value
user_pass = xmldoc.SelectSingleNode("/prop/code/user@password").Value
Now, for the sake of an example, if we had multiple rate records to process in the rates section, we could handle that like so:
Code:
Dim rate, ratelist
Set ratelist = xmldoc.SelectNodes("/prop/rates/rate")
'process each element in this list
' lets pretend that rate has:
' attributes: start, end (optional), price
' children: optional name tag for the "Super Special Summer Saving Rate" or whatever
'
' <rate start="123" end="123" price="123">
' <name>whatever</name>
' </rate>
Dim rate_name, rate_start, rate_end, rate_price
For Each rate in ratelist
rate_start = rate.attributes.getNamedItem("rate_start").Text
If Not isNull(rate.attributes.getNamedItem("rate_end")) Then
rate_end = rate.attributes.getNamedItem("rate_end").Text
End If
rate_start = rate.attributes.getNamedItem("rate_price").Text
If rate.hasChildNodes() Then
rate_name = rate.childNodes(0).childNodes(0).Text
End If
'Do something with the data
Next
Now an explanation. Elements do have a getAttribute() function that would have been shorter than using the attributes node list, but I wanted to keep the lines consistent. With DOM there is always about 3 differant ways to do things, sometimes because MS has added functions to their DOM that others don't have in an attempt to make it easier for us.
Everything is a node. Obvious your XML elements are a node, but so are your attributes, the text inside your elements, everything.
So when we pulled back an attribute what we really wanted was the text from inside that attribute node. However, when we pulled in our fictional "name" element we had to then get it's first child (a text node) and then get the text from inside that node. I remember this confused the hell out of me for years, but as long as you remember that everything is a node, even text, then that will help.
Next, I shortcut a little by just checking if there were any children in the rate element and then assuming if there were it was the name tag. Since my exmaple only had the one possibility tat would normally work out just fine. In a situation where you had multiple required and/or optional elements inside the rate element, that obviously would not work so well. You have the option of using selectNode, looping through childNodes, and several others in order to find out if your optional elements are there.
Watever you do, don't do anything like:
myvar = rates.getSingleNode("name").childNodes(0).text
because ASP will blow up in your face the first time you run into a "rate" element with no "name" element. Apparently null doesn'thave a method or collection called childNodes
In any case, hopefully this will be enough to get you started. If you have any further quetions definately post back and we'll see what w can do.
-T