using xml data in codedom created class

This is a discussion on using xml data in codedom created class within the C# Programming forums, part of the General Programming Boards category; hi there! i'm creating c# class using codedom methods i have already generated: public class CRSHorizontalID { public class Norway ...

  1. #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

  2. #2
    ...and never returned. StainedBlue's Avatar
    Join Date
    Aug 2009
    Posts
    168
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Send data with class
    By Ducky in forum Networking/Device Communication
    Replies: 6
    Last Post: 08-08-2009, 09:16 AM
  2. Replies: 3
    Last Post: 10-31-2005, 11:05 AM
  3. Replies: 1
    Last Post: 11-23-2003, 07:51 AM
  4. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 05:03 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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