Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

defining struct in XML

Status
Not open for further replies.

RanchuPanchu

Programmer
Jun 2, 2007
5
IL
Hello,



I am new to XML.

I am working on a project of a packet sniffer, and I have a set of messeges with specific structures (which is actually the data in these IP packets).

I thought that defining these messeges struct in XML, will make my code more generic.

Can you refer me maybe to an example as to how in XML , I can define a structure (if I don't use XML, and only hardcoded the structure, it would look like this:



[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct EventLogRecord
{
public uint Length;
public uint Opcode;
public uint RecordNumber;
public uint TimeGenerated;
public uint TimeWritten;
public uint EventID;

}



and how I can then create such structure from what I defines in the XML, (in order to read data into struct).



Thank you for the help,


Ran

 
are you communicating in a homogeneous environment? (.net framework) if so I would recommend remoting over XML. XML is an ideal option for heterogeneous environments.

remoting will provide greater communication efficiency because it will not need to (de)serialize the data.

If you do need XML the format can be what ever you want. For more details on XML I would recommend W3C School's tutorial and Forum426 for more details with that.

for c# the XmlDocument is easy to use, but very slow. if you need forward only read/write to simply load the data into your structure use the XMLReader/XmlWriter objects.

There is also the JSON format which is gaining more populatiry. It has been described as XML w/out the fat. Mostly used with web services.

I can't find the article but MSDN has some useful papers on remoting in .net.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
in order to create structures, there is the xsd command line tool in the Visual studio installation.

You can either pass it a class file and get the xml, or the xml and get a class file iirc

hth

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top