sherrick123
asked on
populating a node list
Help Please.
Hello XML'ers
I am pulling my hair out trying to figure out how to populate a NodeList object with all the YEARS from this following xml document.
I will pass the sFile variable to the object
I want all the "Survey year" nodes from the Structure Name
This is the VBA routine that i have. I am already loaded the XML file
Dim oYearNodeList As MSXML2.IXMLDOMNodeList
Dim sfile As String 'FileSystemObject
myXML.validateOnParse = False
sfile = ActiveDesignFile.Name
Set myXElem = myXML.documentElement
On Error GoTo BADTHINGS
Set oYearNodeList = myXML.selectNodes("Bridge_ Scour/Stru cture[@Nam e='" & sfile & "']/Surveys[@year= " * "]
Debug.Print "how"
BADTHINGS:
MsgBox Error
End Sub
<?xml version="1.0"?>
<!DOCTYPE Bridge_Scour SYSTEM "Bridge_Scour.dtd">
<Bridge_Scour>
<Structure Name = "uw1.dgn">
<Surveys year="2000">
<Survey>
<Entry><Station>0</Station > <Elevation>926.7</Elevatio n></Entry>
<Entry><Station>17</Statio n> <Elevation>925.1</Elevatio n></Entry>
<Entry><Station>32</Statio n> <Elevation>922.7</Elevatio n></Entry>
<Entry><Station>47</Statio n> <Elevation>916.7</Elevatio n></Entry>
<Entry><Station>62</Statio n> <Elevation>911.6</Elevatio n></Entry>
<Entry><Station>100</Stati on> <Elevation>909.8</Elevatio n></Entry>
</Survey>
</Surveys>
<Surveys year="2001">
<Survey>
<Entry><Station>0.3</Stati on> <Elevation>123.47</Elevati on></Entry >
<Entry><Station>0.4</Stati on> <Elevation>123.48</Elevati on></Entry >
</Survey>
</Surveys>
</Structure>
<Structure Name = "uw2.dgn">
<Surveys year="2001">
<Survey>
<Entry><Station>0.5</Stati on> <Elevation>123.49</Elevati on></Entry >
<Entry><Station>0.6</Stati on> <Elevation>123.50</Elevati on></Entry >
</Survey>
</Surveys>
</Structure>
</Bridge_Scour>
PLEASE HELP..
Thanks so much
If i could give a thousand points i would.
Hello XML'ers
I am pulling my hair out trying to figure out how to populate a NodeList object with all the YEARS from this following xml document.
I will pass the sFile variable to the object
I want all the "Survey year" nodes from the Structure Name
This is the VBA routine that i have. I am already loaded the XML file
Dim oYearNodeList As MSXML2.IXMLDOMNodeList
Dim sfile As String 'FileSystemObject
myXML.validateOnParse = False
sfile = ActiveDesignFile.Name
Set myXElem = myXML.documentElement
On Error GoTo BADTHINGS
Set oYearNodeList = myXML.selectNodes("Bridge_
Debug.Print "how"
BADTHINGS:
MsgBox Error
End Sub
<?xml version="1.0"?>
<!DOCTYPE Bridge_Scour SYSTEM "Bridge_Scour.dtd">
<Bridge_Scour>
<Structure Name = "uw1.dgn">
<Surveys year="2000">
<Survey>
<Entry><Station>0</Station
<Entry><Station>17</Statio
<Entry><Station>32</Statio
<Entry><Station>47</Statio
<Entry><Station>62</Statio
<Entry><Station>100</Stati
</Survey>
</Surveys>
<Surveys year="2001">
<Survey>
<Entry><Station>0.3</Stati
<Entry><Station>0.4</Stati
</Survey>
</Surveys>
</Structure>
<Structure Name = "uw2.dgn">
<Surveys year="2001">
<Survey>
<Entry><Station>0.5</Stati
<Entry><Station>0.6</Stati
</Survey>
</Surveys>
</Structure>
</Bridge_Scour>
PLEASE HELP..
Thanks so much
If i could give a thousand points i would.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi sherrick123,
> Set oYearNodeList = myXML.selectNodes("Bridge_ Scour/Stru cture[@Nam e='"
> & sfile & "']/Surveys[@year= " * "]
since we don't sem to get there the preceding-sibling way...
you can't use the '*' as a wildcard in XPath
just leaving that part out will give you all the surveys/@year
Set oYearNodeList = myXML.selectNodes("Bridge_ Scour/Stru cture[@Nam e='" & sfile & "']/Surveys/@year")
will give you a list of years, not necessarily unique
you can then create an array of unique values from this nodeset
by looping over the nodeset and creatin a new item on the other array, if the value does not yet exist
I am still wondering why we can't get the preceding-sibling to work though...
Cheers!
> Set oYearNodeList = myXML.selectNodes("Bridge_
> & sfile & "']/Surveys[@year= " * "]
since we don't sem to get there the preceding-sibling way...
you can't use the '*' as a wildcard in XPath
just leaving that part out will give you all the surveys/@year
Set oYearNodeList = myXML.selectNodes("Bridge_
will give you a list of years, not necessarily unique
you can then create an array of unique values from this nodeset
by looping over the nodeset and creatin a new item on the other array, if the value does not yet exist
I am still wondering why we can't get the preceding-sibling to work though...
Cheers!
sherrick123,
oh man I am late....
ignore my previous message
(and after that this one as well :-)
oh man I am late....
ignore my previous message
(and after that this one as well :-)
ASKER