XML Parsing

J

Jose Cintron

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>
 
G

Guest

Jose Cintron said:
...
..\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
 
J

Jose Cintron

Thanks a million... Changed the line to
XmlReader^ rdr = XmlReader::Create("Vulnerabilities.xml");
and all of the sudden it works.
 
J

Jose Cintron

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.
 

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