Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XML querying through Visual Basic

Posted on 2002-06-05
4
Medium Priority
?
182 Views
Last Modified: 2013-11-25
Hi,

I have one XML loaded in a DOMDocument object. I am using MSXML3. The xml is in following format

<Output>
    <Child>
        <children>
        </children>
    </Child>
    <Child>
        <children>
        </children>
        <children>
        </children>
        <children>
        </children>
    </Child>
    <Child>
        <children>
        </children>
    </Child>
</Output>

I want to take in the NodeList object only those Child Nodes having more than 1 children nodes. I tried to do a selectNodes on the Document object with patterns . But in vain. Can anyone give me the appropriate selectNodes query

Note : I dont want to write a loop and then find the length etc.
thanks,
0
Comment
Question by:Pankaj27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 7055689
<interesting..>
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7056366
Dim xmlDoc As MSXML2.DOMDocument
Dim xmlNodes As MSXML2.IXMLDOMNodeList
Dim xmlNode As MSXML2.IXMLDOMNode

Set xmlDoc = New MSXML2.DOMDocument
If xmlDoc.Load("c:\temp\temp.xml") Then
    Set xmlNodes = xmlDoc.selectNodes("/Output/Child")
    For Each xmlNode In xmlNodes
        If xmlNode.childNodes.length > 1 Then
            Debug.Print "this node has more than one child"
        End If
    Next
Else
    Debug.Print "Unable to load XML doc"
End If
Set xmlDoc = Nothing

Anthony
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 150 total points
ID: 7056741
I'm just thinking out loud here...

I don't know of a particular query to pull this off, but you may be able to do something like:

Set xmlNodes = xmlDoc.SelectNodes("/Output/Child/Children[2]")

to get an array of "Children" nodes that are the second child of a "Child" element (since only "Child" objects with more than one "Children" items can ever have a second child).  You can use this array and loop through it but instead of using the each node object directly, you can grab:

xmlNode.parentNode
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7858097
Hi Pankaj27,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: acperkins@devx and AzraSound

Pankaj27, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question