all groups > dotnet xml > july 2004 >
You're in the

dotnet xml

group:

Element vs Node?



Element vs Node? Wayne Wengert
7/29/2004 7:13:56 AM
dotnet xml: I am trying to pull data from child nodes but I cannot find the syntax that
works. I think I may be confusing elements and nodes? I want to get the
value of the items in the <Sched> child nodes. The relevant part of my code
are below as well as a part of the source xml.


=============== Code ==============================

Dim objDom As DOMDocument
Dim y As IXMLDOMElement
Dim x As IXMLDOMElement
Dim j as Integer

Set objDom = New DOMDocument
objDom.async = False
objDom.Load (inputfile)
Set objRootElement = objDom.documentElement
For Each x In objRootElement.childNodes
........
Select Case x.childNodes.Item(j).nodeName
......
Case "Sched"
For Each y In x.childNodes.Item(j) '<==== Error: "object
doesn't support this property or method"
xxx = y.childNodes.Item(1).Text
Next
Next

================ Sample XML ================
<?xml version="1.0" ?>
<root>
<base>
<SeqNbr>1</SeqNbr>
<PorF>P</PorF>
<Round>1</Round>
<Sched>
<ID>10</ID>
<Nickname>Group A</Nickname>
<Class>AAA</Class>
</Sched>
<Sched>
<ID>23</ID>
<Nickname>Group J</Nickname>
<Class>AAA</Class>
</Sched>
</base>
<base>
<SeqNbr>2</SeqNbr>
<PorF>F</PorF>
<Round>0</Round>
<Sched>
<ID>16</ID>
<Nickname>Group C</Nickname>
<Class>AA</Class>
</Sched>
<Sched>
<ID>27</ID>
<Nickname>Group D</Nickname>
<Class>AA</Class>
</Sched>
</base>

<base>
<SeqNbr>3</SeqNbr>
<PorF>P</PorF>
<Round>4</Round>
<Sched>
<ID>31</ID>
<Nickname>Group F</Nickname>
<Class>BB</Class>
</Sched>
<Sched>
<ID>23</ID>
<Nickname>Group G</Nickname>
<Class>BB</Class>
</Sched>
</base>



Re: Element vs Node? Derek Harmon
7/29/2004 11:11:13 PM
[quoted text, click to view]

More likely, the confusion is between singular and plural.

[quoted text, click to view]

Observe here that x.childNodes.Item( j) has one nodeName.
This suggests it's "one" item.

[quoted text, click to view]

Here you are doing a For Each, which requires an enumerable
object like IXMLDOMNodeList (a list of nodes). However, you
are specifying x.childNodes.Item( j) which is an IXMLDOMNode
(individual node). Because it's a singular object, the "method" it
doesn't support is being enumerated.

I'm taking a guess that what you might want is..

' The children of <Sched>
For Each y In x.childNodes.Item( j).childNodes


Wayne, you might also be able to find better/faster answers in
microsoft.public.xml, since your question concerns VBScript
and MSXML (and isn't really about the .NET Framework's
XML stack).


Derek Harmon

Re: Element vs Node? Wayne Wengert
7/30/2004 12:05:01 PM
Derek;

Thanks for the reply. I suspect your observation is right on. I'll go back
and try to re-think that whole process with your advice in mind.

Wayne

[quoted text, click to view]

AddThis Social Bookmark Button