Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter results for getElementByTagName (DOM)

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
For an example of what I am trying to do, here is some sample code to give you a better idea...
Code:
<OBJECTS>
  <OBJECT>
    <NAME>Object1</NAME>
    <USER>[b]Josh1[/b]</USER>
  </OBJECT>
  <OBJECT>
    <NAME>Object2</NAME>
    <USER>[b]Josh2[/b]</USER>
  </OBJECT>
  <OBJECT>
    <NAME>Object3</NAME>
    <USER>[b]Josh1[/b]</USER>
    <USER>[b]Josh2[/b]</USER>
  </OBJECT>
  <OBJECT>
    <NAME>Object4</NAME>
    <USER>[b]Josh1[/b]</USER>
    <USER>[b]Josh3[/b]</USER>
    <USER>[b]Josh4[/b]</USER>
  </OBJECT>
</OBJECTS>

Now if you run this code...
Code:
xmlDOM.documentElement.getElementsByTagName("USER")

it will return these objects:
Code:
<USER>[b]Josh1[/b]</USER>
<USER>[b]Josh2[/b]</USER>
<USER>[b]Josh1[/b]</USER>
<USER>[b]Josh2[/b]</USER>
<USER>[b]Josh1[/b]</USER>
<USER>[b]Josh3[/b]</USER>
<USER>[b]Josh4[/b]</USER>

Is there a way to filter the results down to this...
Code:
<USER>[b]Josh1[/b]</USER>
<USER>[b]Josh2[/b]</USER>
<USER>[b]Josh3[/b]</USER>
<USER>[b]Josh4[/b]</USER>

I am trying to make a drop down list (ListUser), so that when you click on a User's name, I can display the 'Objects' they use in a second List (ListObjects)...
The VB code will probably look something like this...
Code:
Set Objs = xmlDOM.documentElement.getElementsByTagName("OBJECT")
ListObjects.Clear 'Clear the target list
For Each Obj in Objs
  Set Users = Obj.getElementsByTagName("USER")
  For Each User in Users
    If User.Text = ListUser.Text Then
      ListObjects.AddItem Obj.getElementsByTagName("NAME")(0).Text
      Exit For
    End If
  Next
Next

...Unless anyone has a better idea ;-)

But I need to remove the duplicate names from the list...

My goal is for the User List to look like this:
Code:
Josh1
Josh2
Josh3
Josh4

Then when you click Josh1, the Object list will look like this:
Code:
Object1
Object3
Object4


I could do this by looping through and checking to see if I have already added the names to the list before adding another, but I was curious to see if there was a simpler method to speed things up a little ;-)

Thanks in Advance,
Josh

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Thanks, but that query just returned errors...
It did not likr this area, at all:
(.=preceding::USER[1])
especially the ::

Can you use an XSL with DOM in VB (Not a web page)?
I have not really used an XSL before...

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
This works for now...
Code:
    Set Nodes = xmlDOM.documentElement.getElementsByTagName("USER")
    UserList.AddItem "All"
    For Each Node In Nodes
      If Node.Text <> "" Then
        Used = False
        For i = 0 To UserList.ListCount - 1
          If UserList.List(i) = Node.Text Then Used = True: Exit For
        Next
        If Not Used Then UserList.AddItem Node.Text
      End If
    Next
    UserList = UserList.List(0)

And the Sorted attribute on the list control is set to True so that takes care of that...

So I think I am going to go with this for the moment, unless anyone else has a better method...

Thanks,
Josh

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top