views:

166

answers:

2

Hi,

If I have an xml file like this:

<?xml version="1.0" ?>
  <CATALOG>  
    <TITLE>Title1/TITLE>  
    <COUNTRY>USA</COUNTRY>
  </CaTALOG>
</xml>

can I call Catalog tag like a class name from intellisense when I edit c# application ? and his child Title1 and USA ?

Example with intellisense VS 2008 c# :

1) System.DateTime.Now;

2) and in my case: Catalog Catalog.Title1 Catalog.USA

and the MOST important thing is: I don't need to have any assembly references or no implemented classes. I must to solve this task only with xml files without dlls or classes. It's possible? and how?

Thanks!

A: 

It's not possible without coding it yourself in a wrapper class. The closest you'll get it linq to xml, but of course, thats an assembly you'd need to register!

Paul Creasey
+2  A: 

you can do something as follows

 XDocument catalogueXml
                  = XDocument.Load("books.xml");
   CatalogItem item = (from catalog in
                                    catalogueXml.Descendants("CATALOG")
                      select new CatalogItem
                      {
                        Name = catalog.Element("TITLE").Value,
                        Country = catalog.Element("COUNTRY").Value
                      }).FirstOrDefault();

you can still get anonymous object but better to have a defined class

 public class CatalogItem
 {  
   public string Name { get; set; } 
   public string Country { get; set; }
 }

for step by step process and better insight, this is a must have read

Asad Butt