all groups > dotnet xml > june 2006 >
You're in the

dotnet xml

group:

How do I parse an XML file


How do I parse an XML file Jose Cintron
6/27/2006 5:38:49 PM
dotnet xml:
The XML file looks something like this...

--- Start XML ---
<?xml version=3D"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 =3D 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=20

--- 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. =
Re: How do I parse an XML file Oleg Tkachenko [MVP]
6/29/2006 4:55:16 PM
[quoted text, click to view]

XmlReader is an abstract class, use XmlReader::Create() method to
instantiate XmlReader instance.

--
Oleg Tkachenko [XML MVP, MCPD]
AddThis Social Bookmark Button