Re: Read XML file using OOP
- From: "*** Swager" <cswager.n.o.s.p.a.m@xxxxxxx>
- Date: Sat, 26 Apr 2008 10:33:08 -0400
using namespace System::Xml; // XmlTextReader, XmlValidatingReader
....
void XmlStuff (String^ xmlFilename)
{
try
{
// Open the XML file that has the XML text.
XmlDocument^ doc = gcnew XmlDocument ();
doc->Load (xmlFilename);
XmlNode^ carNode = doc->SelectSingleNode ("/carlot/car");
if (!carNode
return;
// Get the make of the car.
string make = gcnew String carNode->Attributes ["Make"]->Value);
...
}
catch (Exception^ e)
{
throw gcnew Exception ("Could not obtain info from the XML file: " + xmlFilename, e);
}
}
"Tammy Nejadian" <TammyNejadian@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:3002469F-459F-46EE-8AAE-73D4B26B55A2@xxxxxxxxxxxxxxxx
Hi,
I am using visual studio C# window and I have an xml file which I need to
read that file using Object Oriented program. What codes I should use in my
class to load and read that xml file. Thanks
My xml file call carsXml.xml and it includes below information:
<?xml version="1.0" encoding="utf-8" ?>
<carlot>
<car>
<Make>OldsMobile</Make>
<Model>Cutlas</Model>
<Milage>5000</Milage>
</car>
<car>
<Make>Chevelate</Make>
<Model>Camro</Model>
<Milage>6000</Milage>
</car>
</carlot>
My Class calls carClass however it is not completed. I dont know how to lead
that xml file here to read it. The codes I have are:
class carClass
{
//Field
private string _model;
private string _make;
private int _milage;
//properties
public string Model
{
get { return _model; }
set { _model = value; }
}
public string Make
{
get { return _make; }
set {_make = value; }
}
public int Milage
{
get { return _milage; }
set { _milage = value;}
}
}
--
Nejadian
.
- References:
- Read XML file using OOP
- From: Tammy Nejadian
- Read XML file using OOP
- Prev by Date: Re: Windows Presentation Foundation
- Next by Date: Re: Read XML file using OOP
- Previous by thread: Re: Read XML file using OOP
- Next by thread: Re: Read XML file using OOP
- Index(es):