The XML file looks something like this...
--- Start XML ---
<?xml version="1.0" ?>
<VULNERABILITIES>
<PROGRAM_VERSION>0.0.1</PROGRAM_VERSION>
<CONTROL_VERSION>0.0.1</CONTROL_VERSION>
<VULNERABILITY>
<V_SHORT_NAME>SOMETHING</V_SHORT_NAME>
<V_LONG_NAME>SOMETHING</V_LONG_NAME>
<V_DISCUSSION>NICE DESCRIPTION</V_DISCUSSION>
<V_REFERENCE>
<V_CATEGORY>SOMETHING</V_CATEGORY>
<ID>1</ID>
</VULNERABILITY>
<VULNERABILITY>
<V_SHORT_NAME>SOMETHING</V_SHORT_NAME>
<V_LONG_NAME>SOMETHING</V_LONG_NAME>
<V_DISCUSSION>NICE DESCRIPTION</V_DISCUSSION>
<V_REFERENCE>
<V_CATEGORY>SOMETHING</V_CATEGORY>
<ID>2</ID>
</VULNERABILITY>
.
.
.
</VULNERABILITIES>
--- End XML ---
The code I have looks like this...
--- Start Code ---
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
#using <System.xml.dll>
using namespace System::Xml;
int _tmain(int argc, _TCHAR* argv[])
{
try
{
// Create the reader...
XmlReader^ rdr = gcnew XmlReader("Vulnerabilities.xml");
while (rdr->ReadToFollowing("VULNERABILITY"))
{
Console::WriteLine(rdr->GetAttribute("ID"));
}
}
catch (Exception^ pe)
{
Console::WriteLine(pe->ToString());
}
return 0;
}
--- End Code ---
I created the code by looking a some MSDN examples. For now all I want is
to be able to move from one VULNERABILITY block to the next and print the
ID. Eventually this will be used to generate a report by cross referencing
an file that only has the IDs in it. The error that I'm getting is
--- Start error ---
.\XMLparse.cpp(16) : error C3622: 'System::Xml::XmlReader': a class declared
as 'abstract' cannot be instantiated
c:\windows\microsoft.net\framework\v2.0.50727\system.xml.dll : see
declaration of 'System::Xml::XmlReader'
.\XMLparse.cpp(16) : error C3673: 'System::Xml::XmlReader' : class does not
have a copy-constructor
--- End error ---
Just in case it makes a difference I'm using Visual C++ Express Edition.
Any ideas will be greatly appreciated
> ...
> ..\XMLparse.cpp(16) : error C3622: 'System::Xml::XmlReader': a class declared
> as 'abstract' cannot be instantiated
Correct. You can't directly create XmlReader objects with gcnew.
> ..\XMLparse.cpp(16) : error C3673: 'System::Xml::XmlReader' : class does not
> have a copy-constructor
Also correct, because XmlReader is abstract.
> Just in case it makes a difference I'm using Visual C++ Express Edition.
> Any ideas will be greatly appreciated
See the System::Xml::XmlReader.Create(...) family of methods. You can create
various kinds of XmlReaders there, depending on where your XML is coming from.
Sean
Jose Cintron - 28 Jun 2006 15:16 GMT
Thanks a million... Changed the line to
XmlReader^ rdr = XmlReader::Create("Vulnerabilities.xml");
and all of the sudden it works.
>> ...
>> ..\XMLparse.cpp(16) : error C3622: 'System::Xml::XmlReader': a class
[quoted text clipped - 18 lines]
>
> Sean
Jose Cintron - 28 Jun 2006 16:22 GMT
OK the code looks as follows now...
--- Start Code ---
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.xml.dll>
using namespace System;
using namespace System::Xml;
int _tmain(int argc, _TCHAR* argv[])
{
try
{
// Create the reader...
XmlReader^ rdr = XmlReader::Create("Vulnerabilities.xml");
while (rdr->ReadToFollowing("VULNERABILITY"))
{
Console::WriteLine("ID:" + rdr->GetAttribute("ID"));
}
}
catch (Exception^ pe)
{
Console::WriteLine(pe->ToString());
}
return 0;
}
--- End Code ---
My problem now is with the GetAttribute function. From what I read in MSDN
it should move to the Attribute specified in the string "ID" and return its
value. Is my understanding correct? If it is why is this damn thing not
working? The while loop works just fine and I know that there is an ID
entry for every VULNERABILITY.
>> ...
>> ..\XMLparse.cpp(16) : error C3622: 'System::Xml::XmlReader': a class
[quoted text clipped - 18 lines]
>
> Sean