Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2006

Tip: Looking for answers? Try searching our database.

XML Parsing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jose Cintron - 27 Jun 2006 22:39 GMT
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
Sean M. DonCarlos - 28 Jun 2006 14:37 GMT
> ...
> ..\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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.