Let's say that I have an xml file with:

<PRODUCTS>
<PRODUCT>
<SKU>AAA111</SKU>
<NAME>Name One</NAME>
<COLORS>
<COLOR><ID>BK</ID><PRICE>10</PRICE></COLOR>
<COLOR><ID>WH</ID><PRICE>20</PRICE></COLOR>
</COLORS>
</PRODUCT>
<PRODUCT>
<SKU>BBB222</SKU>
<NAME>Name Two</NAME>
<COLORS>
<COLOR><ID>BK</ID><PRICE>20</PRICE></COLOR>
<COLOR><ID>WH</ID><PRICE>30</PRICE></COLOR>
</COLORS>
</PRODUCT>
<PRODUCTS>

When the session starts, I want to create a Session Variable/Object
that can be used in ASPs later like this:
(Example Use in VBScript)

Dim colProducts
colProducts = Session("PRODUCTS")
For Each oProduct In colProducts
Response.Write(oMyProduct("SKU")
For Each oColor In oProduct("COLORS") ' Access a SUB collection
directly.
Response.Write(oColor("ID"))
Next
Next

oMyProduct = colProducts("AAA111")
Response.Write(oMyProduct("NAME"))

It has been a very long time since I coded, and so my code is probably
a bit rusty. Also, I have never really worked with collections.

My questions are:

1.) In my session_onstart code, how do I create a collection and store
it into the session variable? What language should I use? Code
Examples?

2.) In my ASPs, how do I propperly access those collections and
sub-collections? Languages? Code Examples?

Thanks in advance.

Re: Collections in ASP and XML, using the Session Object (Part 1) by Anthony

Anthony
Tue Jan 23 04:03:06 CST 2007


"Beav" <levibeckman@gmail.com> wrote in message
news:1169497543.810689.151560@m58g2000cwm.googlegroups.com...
> Let's say that I have an xml file with:
>
> <PRODUCTS>
> <PRODUCT>
> <SKU>AAA111</SKU>
> <NAME>Name One</NAME>
> <COLORS>
> <COLOR><ID>BK</ID><PRICE>10</PRICE></COLOR>
> <COLOR><ID>WH</ID><PRICE>20</PRICE></COLOR>
> </COLORS>
> </PRODUCT>
> <PRODUCT>
> <SKU>BBB222</SKU>
> <NAME>Name Two</NAME>
> <COLORS>
> <COLOR><ID>BK</ID><PRICE>20</PRICE></COLOR>
> <COLOR><ID>WH</ID><PRICE>30</PRICE></COLOR>
> </COLORS>
> </PRODUCT>
> <PRODUCTS>
>
> When the session starts, I want to create a Session Variable/Object
> that can be used in ASPs later like this:
> (Example Use in VBScript)
>
> Dim colProducts
> colProducts = Session("PRODUCTS")
> For Each oProduct In colProducts
> Response.Write(oMyProduct("SKU")
> For Each oColor In oProduct("COLORS") ' Access a SUB collection
> directly.
> Response.Write(oColor("ID"))
> Next
> Next
>
> oMyProduct = colProducts("AAA111")
> Response.Write(oMyProduct("NAME"))
>
> It has been a very long time since I coded, and so my code is probably
> a bit rusty. Also, I have never really worked with collections.
>
> My questions are:
>
> 1.) In my session_onstart code, how do I create a collection and store
> it into the session variable? What language should I use? Code
> Examples?

Are you sure you want to use Session? It seems unlikely at the
session_onstart you will have enough info to distinguish that one session
needs one set of data and another a different set.

In fact be sure first of all that this isn't best done simply using a DB.

IOW (if you go ahead) you will more likely want Application_onstart and
store the data in the application object rather than duplicate the same info
across multiple sessions.

Language VBScript

Example:-

Dim oDOM
Set oDOM = Server.CreateObject("MSXML2.FreeThreadDOMDocument.3.0")
oDOM.async = false
oDOM.load Server.MapPath("/data/products.xml")

Set Application("Products") = oDOM

>
> 2.) In my ASPs, how do I propperly access those collections and
> sub-collections? Languages? Code Examples?

Dim oDOM : Set oDOM = Application("Products")

For Each elemProduct In oDOM.selectNodes("//PRODUCT")
For elemColor In elemProduct In elemProduct("COLORS/COLOR")
Response.Write elemColor.selectSingleNode("ID").Text
Next
Next



>
> Thanks in advance.
>



Re: Collections in ASP and XML, using the Session Object (Part 1) by Anthony

Anthony
Tue Jan 23 05:14:55 CST 2007


"Anthony Jones" <Ant@yadayadayada.com> wrote in message
news:O$tuuWtPHHA.4280@TK2MSFTNGP02.phx.gbl...
>
> "Beav" <levibeckman@gmail.com> wrote in message
> news:1169497543.810689.151560@m58g2000cwm.googlegroups.com...
> > Let's say that I have an xml file with:
> >
> > <PRODUCTS>
> > <PRODUCT>
> > <SKU>AAA111</SKU>
> > <NAME>Name One</NAME>
> > <COLORS>
> > <COLOR><ID>BK</ID><PRICE>10</PRICE></COLOR>
> > <COLOR><ID>WH</ID><PRICE>20</PRICE></COLOR>
> > </COLORS>
> > </PRODUCT>
> > <PRODUCT>
> > <SKU>BBB222</SKU>
> > <NAME>Name Two</NAME>
> > <COLORS>
> > <COLOR><ID>BK</ID><PRICE>20</PRICE></COLOR>
> > <COLOR><ID>WH</ID><PRICE>30</PRICE></COLOR>
> > </COLORS>
> > </PRODUCT>
> > <PRODUCTS>
> >
> > When the session starts, I want to create a Session Variable/Object
> > that can be used in ASPs later like this:
> > (Example Use in VBScript)
> >
> > Dim colProducts
> > colProducts = Session("PRODUCTS")
> > For Each oProduct In colProducts
> > Response.Write(oMyProduct("SKU")
> > For Each oColor In oProduct("COLORS") ' Access a SUB collection
> > directly.
> > Response.Write(oColor("ID"))
> > Next
> > Next
> >
> > oMyProduct = colProducts("AAA111")
> > Response.Write(oMyProduct("NAME"))
> >
> > It has been a very long time since I coded, and so my code is probably
> > a bit rusty. Also, I have never really worked with collections.
> >
> > My questions are:
> >
> > 1.) In my session_onstart code, how do I create a collection and store
> > it into the session variable? What language should I use? Code
> > Examples?
>
> Are you sure you want to use Session? It seems unlikely at the
> session_onstart you will have enough info to distinguish that one session
> needs one set of data and another a different set.
>
> In fact be sure first of all that this isn't best done simply using a DB.
>
> IOW (if you go ahead) you will more likely want Application_onstart and
> store the data in the application object rather than duplicate the same
info
> across multiple sessions.
>
> Language VBScript
>
> Example:-
>
> Dim oDOM
> Set oDOM = Server.CreateObject("MSXML2.FreeThreadDOMDocument.3.0")
> oDOM.async = false
> oDOM.load Server.MapPath("/data/products.xml")
>
> Set Application("Products") = oDOM
>
> >
> > 2.) In my ASPs, how do I propperly access those collections and
> > sub-collections? Languages? Code Examples?
>
> Dim oDOM : Set oDOM = Application("Products")
>
> For Each elemProduct In oDOM.selectNodes("//PRODUCT")
> For elemColor In elemProduct In elemProduct("COLORS/COLOR")

Oops should be

For Each elemColor elemProduct.selectNodes("COLORS/COLOR")


> Response.Write elemColor.selectSingleNode("ID").Text
> Next
> Next
>
>
>
> >
> > Thanks in advance.
> >
>
>