|
-
Nov 17th, 2005, 11:44 AM
#1
Thread Starter
Junior Member
XML Question using VB.Net Code
Hi All,
I was wondering if someone might be able to help me with a problem in VB.net code? I have the following XML file:
<Applications>
<ApplicationGroup GroupID="001" GroupName="Oracle SQLNet">
<Application AppName="SQLNet" Version="9.2.0.4">
<Package Name="Oracle SQLNet 9.2.0.4 DBA" id="">
<PackageInfo>
<MarkForUninstall>1</MarkForUninstall>
</PackageInfo>
</Package>
<Package Name="Oracle SQLNet 9.2.0.4 App User Std" id="">
<PackageInfo>
<MarkForUninstall>0</MarkForUninstall>
</PackageInfo>
</Package>
</Application>
</ApplicationGroup>
</Applications>
Im trying to do 2 things through use of the XMLDocument Class and XPath, get the Name attribute from each <Package> and value of <MarkForUninstall> for each of them. Any help would be great.
Thanks,
-ETR
-
Nov 22nd, 2005, 09:04 AM
#2
Hyperactive Member
Re: XML Question using VB.Net Code
This is C# Code but it should be easy for you to translate:
Code:
using System;
using System.Xml;
namespace XMLSample
{
class XMLSample
{
[STAThread]
static void Main(string[] args)
{
XmlDocument myDoc = new XmlDocument();
myDoc.LoadXml("<Applications><ApplicationGroup GroupID=\"001\" GroupName=\"Oracle SQLNet\"><Application AppName=\"SQLNet\" Version=\"9.2.0.4\"><Package Name=\"Oracle SQLNet 9.2.0.4 DBA\" id=\"\"><PackageInfo><MarkForUninstall>1</MarkForUninstall></PackageInfo></Package><Package Name=\"Oracle SQLNet 9.2.0.4 App User Std\" id=\"\"><PackageInfo><MarkForUninstall>0</MarkForUninstall></PackageInfo></Package></Application></ApplicationGroup></Applications>");
foreach(XmlNode myNode in myDoc.SelectNodes("//Package"))
{
string name = myNode.Attributes.GetNamedItem("Name").InnerText;
Console.WriteLine(name);
Console.WriteLine(myNode.SelectSingleNode("//Package[@Name='"+name+"']/PackageInfo/MarkForUninstall").InnerText);
}
Console.ReadLine();
}
}
}
This is just one possible way of doing it, there may be many more.
And of course you need to do some Exception handling in case your XPath Querys wont find a match! If you have any further questions just post!
Stephan
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|