Solved

XML querying through Visual Basic

Posted on 2002-06-05
4
179 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 52

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Error when passing an argument to a vb6 that contains  '/' 7 49
vbModal 12 75
Error with a code discussed on this page 5 51
Mobile apps - web/native or hybrid? 1 121
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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 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