Are you stuck with the way that XML file is laid out or could you
reformat it? If, for example, the <email> nodes where children of the
<siteName> nodes I could write a much better algorithm.
Thanks,
Seth Rowe
> Yeah, it seems like there would be a more elegant way to iterate
> through the list, BUT I AM VERY THANKFUL for what you posted. :) It has
[quoted text clipped - 96 lines]
> > >
> > > Any help is greatly appreciated. Thanks!
Chris Dunaway - 21 Nov 2006 22:25 GMT
> Are you stuck with the way that XML file is laid out or could you
> reformat it? If, for example, the <email> nodes where children of the
[quoted text clipped - 104 lines]
> > > >
> > > > Any help is greatly appreciated. Thanks!
One other thing is that values that would be properties of a node (in
this case active, for example) should be attributes and not nodes. And
rather than call the nodes <sideData> they should probably just be
<site>. And I agree with rowe that the email nodes should themselves
be children of a containing node for example:
<EMailAddresses>
<EMailAddress>blah@blah.com</EMailAddress>
</EMailAddresses>
If the xml were structured this way, you could use an XPath query to
return the exact EMailAddresses node you needed and then iterate
through each address in that node:
Considering this xml:
<?xml version="1.0" encoding="utf-8" ?>
<sites>
<site Name="Flux" Active="True">
<EMailAddresses>
<EMailAddress>me@me.com</email>
<EMailAddress>you@you.com</email>
</EMailAddresses>
</site>
<site Name="Capacitor" Active="False">
<EMailAddresses>
<EMailAddress>yo@yo.com</EMailAddress>
</EMailAddresses>
</site>
<site Name="Scott" Active="True">
<EMailAddresses>
<EMailAddress>you@you.com</EMailAddress>
<EMailAddress>me@me.com</EMailAddress>
<EMailAddress>dupree@dupree.com</EMailAddress>
</EMailAddresses>
</site>
</sites>
<AirCode>
'Load the xml file
Dim xDoc As New XmlDocument
xDoc.Load("xmlfilename.xml")
'Now select the EMailAddresses node for the Site with Name = "Flux"
Dim xNode As XmlNode
xNode = xDoc.SelectSingleNode("\Site[@Name='Flux']\EMailAddresses")
If xNode IsNot Nothing Then
'Iterate through xNodes children here
For Each x As XmlNode In xNode.ChildNodes
Console.WriteLine(x.InnerText)
Next
End If
</AirCode>
You can still use XPath even if the xml is not formatted the way I show
it, but I think, at least, the email addresses should be in a container
node.
Hope this helps a little
Chris