Reading XML file


G

greatbarrier86

Hi,

I have an XML file that looks like this.

<?xml version="1.0" ?>
- <WURedist>
- <StandaloneRedist Version="32">
<architecture name="x86" clientVersion="7.2.6001.788"
downloadUrl="http://download.windowsupdate.com/W...one/7.2.6001.788/WindowsUpdateAgent30-x86.exe" />
<architecture name="x64" clientVersion="7.2.6001.788"
downloadUrl="http://download.windowsupdate.com/W...one/7.2.6001.788/WindowsUpdateAgent30-x64.exe" />
<architecture name="ia64" clientVersion="7.2.6001.788"
downloadUrl="http://download.windowsupdate.com/W...ne/7.2.6001.788/WindowsUpdateAgent30-ia64.exe" />
<MUAuthCab RevisionId="7"
DownloadURL="http://update.microsoft.com/v8/microsoftupdate/redir/MUAuth.cab"
/>
</StandaloneRedist>
</WURedist>

i am trying to get my program to read the x86 line and get the ClientVersion
and DownloadURL from that line, but i dont know how to do it. Can anyone
offer some advice?

Thanks so much,
Jason
 
Ad

Advertisements

M

Martin Honnen

greatbarrier86 said:
i am trying to get my program to read the x86 line and get the ClientVersion
and DownloadURL from that line, but i dont know how to do it. Can anyone
offer some advice?

Which version of the .NET framework do you use? With .NET 3.5 you could
use LINQ to XML, with earlier versions XmlDocument or XPathNavigator.

Here is a LINQ to XML sample:

string n = "x86";
XDocument doc = XDocument.Load(@"..\..\XMLFile1.xml");
XElement arch =
doc.Root.Element("StandaloneRedist").Elements("architecture").Where(a =>
(string)a.Attribute("name") == n).FirstOrDefault();
if (arch != null)
{
Console.WriteLine(
"Client version: {0}; Download URL: {1}",
arch.Attribute("clientVersion").Value, arch.Attribute("downloadUrl").Value);
}
 
Ad

Advertisements

G

greatbarrier86

Wow...nice!! thanks so much for your help!!

Martin Honnen said:
Which version of the .NET framework do you use? With .NET 3.5 you could
use LINQ to XML, with earlier versions XmlDocument or XPathNavigator.

Here is a LINQ to XML sample:

string n = "x86";
XDocument doc = XDocument.Load(@"..\..\XMLFile1.xml");
XElement arch =
doc.Root.Element("StandaloneRedist").Elements("architecture").Where(a =>
(string)a.Attribute("name") == n).FirstOrDefault();
if (arch != null)
{
Console.WriteLine(
"Client version: {0}; Download URL: {1}",
arch.Attribute("clientVersion").Value, arch.Attribute("downloadUrl").Value);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top