Solved

XML querying through Visual Basic

Posted on 2002-06-05
4
177 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
4 Comments
 
LVL 50

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 50 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now