Thank you for your answer.
However I still can't seem to get the contents under <package_article> to be
retrieved.
How would the line
package.GetElementsByTagName("packageid")[0];
be translated into VB.NET ?
Simply changing the syntax to ...(0) does not seem to work.
Normally I would simply use XSL to output the results, but in this case it's
not possible.
"Martin Honnen" wrote:
[color=blue]
>
>
> Andy wrote:
>
>[color=green]
> > I have the following example XML:
> > <data>
> > <package>
> > <packageid>123</packageid>
> > <package_article>
> > <articleid>article1</articleid>
> > </package_article>
> > </package>
> >
> > <package>
> > <packageid>456</packageid>
> > <package_article>
> > <articleid>article2</articleid>
> > </package_article>
> > </package>
> > </data>
> >
> > I want to be able to list the following to the client, based on the above xml:
> > Package: 123
> > Article: article1
> > Package: 456
> > Article: article2[/color]
>
> GetElementsByTagName is not only a method of the document itself but of
> any element node so you can use that as follows (C# code):
>
> XmlDocument xmlDocument = new XmlDocument();
> xmlDocument.Load(@"test2005070301.xml");
> foreach (XmlNode node in xmlDocument.GetElementsByTagName("package")) {
> XmlElement package = node as XmlElement;
> XmlElement packageid = (XmlElement)
> package.GetElementsByTagName("packageid")[0];
> if (packageid != null) {
> Console.WriteLine("Package: {0}", packageid.InnerText);
> }
> XmlElement articleid = (XmlElement)
> package.GetElementsByTagName("articleid")[0];
> if (articleid != null) {
> Console.WriteLine("Article: {0}", articleid.InnerText);
> }
> Console.WriteLine();
> }
>
> But as .NET implements XPath it is usually easier and more elegant to
> solve such tasks with XPath:
>
> XmlDocument xmlDocument = new XmlDocument();
> xmlDocument.Load(@"test2005070301.xml");
> foreach (XmlNode node in xmlDocument.SelectNodes("/data/package")) {
> XmlElement package = node as XmlElement;
> XmlElement packageid = (XmlElement)
> package.SelectSingleNode("packageid");
> if (packageid != null) {
> Console.WriteLine("Package: {0}", packageid.InnerText);
> }
> XmlElement articleid = (XmlElement)
> package.SelectSingleNode("package_article/articleid");
> if (articleid != null) {
> Console.WriteLine("Article: {0}", articleid.InnerText);
> }
> Console.WriteLine();
> }
>
>
> --
>
> Martin Honnen --- MVP XML
>
http://JavaScript.FAQTs.com/
>[/color]