C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-24-2009, 06:02 AM   #1
Registered User
 
Join Date: Jul 2009
Posts: 2
using xml data in codedom created class

hi there!

i'm creating c# class using codedom methods
i have already generated:

public class CRSHorizontalID
{

public class Norway
{

// value
public const long name;
}
}

bu the name of "public class Norway" should be read from xml document.. the name of class is in the xml node: <Country name="Norway" isoAlpha3="NOR" countryId="47" >

does someone know how could i get the word "Norway" from xml(or xsd) to the:
newClass = new CodeTypeDeclaration(className); ?

thank you much
jimmi666 is offline   Reply With Quote
Old 08-30-2009, 10:55 AM   #2
...and never returned.
 
StainedBlue's Avatar
 
Join Date: Aug 2009
Posts: 41
Code:
using System.Xml.Linq;

//...

string countryName =
  doc.Element("RootElement").Elements("Country")
  .Where(
    p => (string)p.Attribute == (someId)
  ).Select(
    p => (string)p.Attribute("name")
    ).SingleOrDefault();

newClass = new CodeTypeDeclaration(countryName);
Note that the above requires you to know what you're looking for, otherwise you'll have to return an IEnumerable collection and iterate all values (which may be what you're looking for), the latter allows you to have an in memory representation of the xml document, allowing you to parse it with just c#

Last edited by StainedBlue; 08-30-2009 at 11:07 AM.
StainedBlue is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Send data with class Ducky Networking/Device Communication 6 08-08-2009 09:16 AM
Polymorphism Theory Question - Polymorphic Class Definition. ventolin C++ Programming 3 10-31-2005 12:05 PM
VC++ Sending data from a structure in one class to a ListBox in a second class. Burlock Windows Programming 1 11-23-2003 08:51 AM
can't insert data into my B-Tree class structure daluu C++ Programming 0 12-05-2002 06:03 PM
structure vs class sana C++ Programming 13 12-02-2002 07:18 AM


All times are GMT -6. The time now is 04:12 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22