Re: Assigning Attributes

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Al Dunbar [MS-MVP] (alan-no-drub-spam_at_hotmail.com)
Date: 06/05/04


Date: Sat, 5 Jun 2004 00:29:27 -0600


"Cheryl" <chawes7420@aol.com> wrote in message
news:77d23bf5.0406040616.4876233a@posting.google.com...
> Thanks for replying. The xml document is being loaded from a file.
> The tag Category has no value only the attribute "ID" that I need to
> retrieve from this xml string and assign to a variable.
>
> Dim xmlDoc
> Dim root
> Set XMLDoc = createobject("Msxml2.DOMDocument.4.0")
> set root = xmlDoc.documentElement
> xmlDoc.async = False
> xmlDoc.resolveExternals = False
> xmlDoc.Load ("C:\Catogory.xml")

I guess actual filenames may be misspellings of words, but since I cannot
see your C: drive, I would suggest you double check this.

> set child = root.selectNodes ("category")
> if category then

I understand that the literal string "category" is used to refer to an
element in your XML file, but in the statement above "if category then", the
word category is being interpretted by your vbscript as a vbscript variable.
Since you do not seem to have given it a value, you might want to be
suspicious of this statement.

/Al

> name = child.getattribute("category[@id]")
> end if
>
> ***** This is the xml file****
> <Catagories>
> - <Category id="1">
> <Subcategory attrib="2" />
> </Category>
> </Catagories>
> ****************************
>
>
> "Al Dunbar [MS-MVP]" <alan-no-drub-spam@hotmail.com> wrote in message
news:<OaSbUneSEHA.1764@TK2MSFTNGP10.phx.gbl>...
> > "Cheryl" <chawes7420@aol.com> wrote in message
> > news:77d23bf5.0406031221.ef3ac92@posting.google.com...
> > > <Catagories>
> > > - <Category id="1">
> > > <Subcategory attrib="2" />
> > > </Category>
> > > </Catagories>
> >
> > That minus sign should not actually be *in* your document - that is just
how
> > IE displays xml.
> >
> > > Please somebody help! This is my xml document want I'm trying to do is
> > > to assign the value of the attribute "id" to a variable. So that I can
> > > pass this information along to other components. I've come up the
> > > following code but, the variable "name" is empty??
> > >
> > > if category then
> > > name = child.getattribute("category[@id]")
> > > end if
> >
> > Seems to me that you are not giving enough details. Like, how has the
xml
> > document been loaded? How does variable "category" come to have a value,
and
> > what is it?
> >
> > /Al


Quantcast