Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XML querying through Visual Basic

Posted on 2002-06-05
4
Medium Priority
?
183 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 54

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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

885 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