syedahmed
October 26th, 2005, 12:51 PM
I have a xml file whichi want to parse and print the output by filtering the first xml file.The first file looks like this
<XMLOut>
<Check ID="500" Grade="3" Type="5" Cat="1" Rank="1" Name="Scanning Requirements" URL1="Help/Check5311.html" URL2="Help/Check5311fix.html" GroupID="MBSA:Required" GroupName="Scanning Requirements">
<Advice>1 scanning requirements are missing. A complete scan could not be performed.</Advice>
<Detail>
<UpdateData ID="MSI" GUID="MBSA:Requirement:MSI" BulletinID="" KBID="MSI" Type="2" IsInstalled="false" Severity="0" RestartRequired="false">
<Title>Windows Installer is required for scanning products installed on the computer</Title>
<References>
<InformationURL>http://go.microsoft.com/fwlink/?LinkId=43035</InformationURL>
<DownloadURL>http://go.microsoft.com/fwlink/?LinkId=42542</DownloadURL>
</References>
</UpdateData>
</Detail>
</Check>
<Check ID="500" Grade="2" Type="5" Cat="1" Rank="1" Name="Windows Security Updates" URL1="Help/Check5311.html" URL2="Help/Check5311fix.html" GroupID="6964aab4-c5b5-43bd-a17d-ffb4346a8e1d" GroupName="Windows">
<Advice>12 security updates are missing. 2 service packs or update rollups are missing.</Advice>
<Detail>
<UpdateData ID="MS02-009" GUID="d5982290-f83a-47a4-b724-0033e1632125" BulletinID="MS02-009" KBID="318089" Type="1" IsInstalled="true" Severity="0" RestartRequired="false">
<Title>Security Update, February 14, 2002 (Internet Explorer 5.5)</Title>
<References>
<BulletinURL>http://www.microsoft.com/technet/security/bulletin/MS02-009.mspx</BulletinURL>
<InformationURL>http://www.download.windowsupdate.com/msdownload/update/v3/static/RTF/en/5223.htm</InformationURL>
<DownloadURL>http://www.download.windowsupdate.com/msdownload/update/v3-19990518/cabpool/vbs55nen_a76b47d34e497bb2c14ba3cbed923cc042406c8b.exe</DownloadURL>
</References>
</UpdateData>
<UpdateData ID="MS02-009" GUID="2e6cc164-d17d-4ada-b8f2-e76b374d3479" BulletinID="MS02-009" KBID="318089" Type="1" IsInstalled="true" Severity="0" RestartRequired="false">
<Title>Security Update, February 14, 2002 (Internet Explorer 6)</Title>
<References>
<BulletinURL>http://www.microsoft.com/technet/security/bulletin/MS02-009.mspx</BulletinURL>
<InformationURL>http://www.download.windowsupdate.com/msdownload/update/v3/static/RTF/en/5226.htm</InformationURL>
<DownloadURL>http://www.download.windowsupdate.com/msdownload/update/v3-19990518/cabpool/vbs56nen_60dd81fed024143825a697259a3dfb0eb9f530f5.exe</DownloadURL>
</References>
</UpdateData>
</Detail>
</Check>
</XMLOut>
and i want ouput file to have only the value of KBID and download Url.
The problem is when i tried to do that and try to parse the node of nodeset .It says "token doesn't match format of a 'Step'"
My code is as follows .Pls help me in this.
use XML::XPath;
use XML::XPath::XMLParser;
use LWP::Simple;
use Win32::OLE qw(in with);
use Win32::Internet;
use Win32;
use File::Spec::Functions;
use File::Copy;
Win32::SetCwd("/temp");
my $xpath = XML::XPath->new("c:/temp/results.xml");
my $nodeset = $xpath->find('/XMLOut/Check[@Grade="2"]/Detail/UpdateData');
print "nodebefore\n";
foreach my $node ($nodeset->get_nodelist){
$element= XML::XPath::XMLParser::as_string($node);
my $xp = XML::XPath->new(context => $element );
my $nodeset1 = $xp->find("//@KBID");
print "$nodeset1\n";
$firstelement= XML::XMLParser::as_string($nodeset1);
print "$firstelement\n";
}
Thanks.
Waiting Impatiently.........
<XMLOut>
<Check ID="500" Grade="3" Type="5" Cat="1" Rank="1" Name="Scanning Requirements" URL1="Help/Check5311.html" URL2="Help/Check5311fix.html" GroupID="MBSA:Required" GroupName="Scanning Requirements">
<Advice>1 scanning requirements are missing. A complete scan could not be performed.</Advice>
<Detail>
<UpdateData ID="MSI" GUID="MBSA:Requirement:MSI" BulletinID="" KBID="MSI" Type="2" IsInstalled="false" Severity="0" RestartRequired="false">
<Title>Windows Installer is required for scanning products installed on the computer</Title>
<References>
<InformationURL>http://go.microsoft.com/fwlink/?LinkId=43035</InformationURL>
<DownloadURL>http://go.microsoft.com/fwlink/?LinkId=42542</DownloadURL>
</References>
</UpdateData>
</Detail>
</Check>
<Check ID="500" Grade="2" Type="5" Cat="1" Rank="1" Name="Windows Security Updates" URL1="Help/Check5311.html" URL2="Help/Check5311fix.html" GroupID="6964aab4-c5b5-43bd-a17d-ffb4346a8e1d" GroupName="Windows">
<Advice>12 security updates are missing. 2 service packs or update rollups are missing.</Advice>
<Detail>
<UpdateData ID="MS02-009" GUID="d5982290-f83a-47a4-b724-0033e1632125" BulletinID="MS02-009" KBID="318089" Type="1" IsInstalled="true" Severity="0" RestartRequired="false">
<Title>Security Update, February 14, 2002 (Internet Explorer 5.5)</Title>
<References>
<BulletinURL>http://www.microsoft.com/technet/security/bulletin/MS02-009.mspx</BulletinURL>
<InformationURL>http://www.download.windowsupdate.com/msdownload/update/v3/static/RTF/en/5223.htm</InformationURL>
<DownloadURL>http://www.download.windowsupdate.com/msdownload/update/v3-19990518/cabpool/vbs55nen_a76b47d34e497bb2c14ba3cbed923cc042406c8b.exe</DownloadURL>
</References>
</UpdateData>
<UpdateData ID="MS02-009" GUID="2e6cc164-d17d-4ada-b8f2-e76b374d3479" BulletinID="MS02-009" KBID="318089" Type="1" IsInstalled="true" Severity="0" RestartRequired="false">
<Title>Security Update, February 14, 2002 (Internet Explorer 6)</Title>
<References>
<BulletinURL>http://www.microsoft.com/technet/security/bulletin/MS02-009.mspx</BulletinURL>
<InformationURL>http://www.download.windowsupdate.com/msdownload/update/v3/static/RTF/en/5226.htm</InformationURL>
<DownloadURL>http://www.download.windowsupdate.com/msdownload/update/v3-19990518/cabpool/vbs56nen_60dd81fed024143825a697259a3dfb0eb9f530f5.exe</DownloadURL>
</References>
</UpdateData>
</Detail>
</Check>
</XMLOut>
and i want ouput file to have only the value of KBID and download Url.
The problem is when i tried to do that and try to parse the node of nodeset .It says "token doesn't match format of a 'Step'"
My code is as follows .Pls help me in this.
use XML::XPath;
use XML::XPath::XMLParser;
use LWP::Simple;
use Win32::OLE qw(in with);
use Win32::Internet;
use Win32;
use File::Spec::Functions;
use File::Copy;
Win32::SetCwd("/temp");
my $xpath = XML::XPath->new("c:/temp/results.xml");
my $nodeset = $xpath->find('/XMLOut/Check[@Grade="2"]/Detail/UpdateData');
print "nodebefore\n";
foreach my $node ($nodeset->get_nodelist){
$element= XML::XPath::XMLParser::as_string($node);
my $xp = XML::XPath->new(context => $element );
my $nodeset1 = $xp->find("//@KBID");
print "$nodeset1\n";
$firstelement= XML::XMLParser::as_string($nodeset1);
print "$firstelement\n";
}
Thanks.
Waiting Impatiently.........