Solved

XML querying through Visual Basic

Posted on 2002-06-05
4
173 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 49

Expert Comment

by:Ryan Chong
Comment Utility
<interesting..>
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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

9 Experts available now in Live!

Get 1:1 Help Now