473,383 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

C# class to Deserialize XML to Object

I started this post in the .net forum, and it was suggested that i post a link here. I could really use some help on this one.

http://www.thescripts.com/forum/show....php?p=2868596

Thanx a bunch,
~~~BillyZ
Oct 9 '07 #1
1 9974
Ok, here is where I'm at, i really need some assistance deserializing this particular xml. I have built the object but there seems to be flaws in the inner portion because i get the data for the variables at the 'siteInfo' level with the exception of the note nodes, and inside the geolocation none of the variables get filled. below are the xml that i am trying to deserialize, followed by the object which i need help with...
XML:
Expand|Select|Wrap|Line Numbers
  1. <sitesResponse xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wtr="http://www.cuahsi.org/waterML/" xmlns="http://www.cuahsi.org/waterML/1.0/">
  2.   <queryInfo>
  3.     <criteria />
  4.   </queryInfo>
  5.   <site>
  6.     <siteInfo>
  7.       <siteName>Owasco Lake Buoy</siteName>
  8.       <siteCode network="FLOWEN" siteID="1">Buoy001</siteCode>
  9.       <geoLocation>
  10.         <geogLocation xsi:type="LatLonPointType" srs="EPSG:26918">
  11.           <latitude>42.853289</latitude>
  12.           <longitude>-76.516628</longitude>
  13.         </geogLocation>
  14.       </geoLocation>
  15.       <verticalDatum>NAVD88</verticalDatum>
  16.       <note title="County">Cayuga</note>
  17.       <note title="State">New York</note>
  18.     </siteInfo>
  19.   </site>
  20.   <site>
  21.     <siteInfo>
  22.       <siteName>OwascoInlet</siteName>
  23.       <siteCode network="FLOWEN" siteID="2">Inlet001</siteCode>
  24.       <geoLocation>
  25.         <geogLocation xsi:type="LatLonPointType" srs="EPSG:26918">
  26.           <latitude>42.716106</latitude>
  27.           <longitude>-76.437281</longitude>
  28.         </geogLocation>
  29.       </geoLocation>
  30.       <note title="County">Cayuga</note>
  31.       <note title="State">New York</note>
  32.     </siteInfo>
  33.   </site>
  34.   <site>
  35.     <siteInfo>
  36.       <siteName>DutchHollowBrook</siteName>
  37.       <siteCode network="FLOWEN" siteID="3">DHB001</siteCode>
  38.       <geoLocation>
  39.         <geogLocation xsi:type="LatLonPointType" srs="EPSG:26918">
  40.           <latitude>42.862406</latitude>
  41.           <longitude>-76.510892</longitude>
  42.         </geogLocation>
  43.       </geoLocation>
  44.       <note title="County">Cayuga</note>
  45.       <note title="State">New York</note>
  46.     </siteInfo>
  47.   </site>
  48.   <site>
  49.     <siteInfo>
  50.       <siteName>IAGT Weather Station</siteName>
  51.       <siteCode network="FLOWEN" siteID="4">CAYUMet</siteCode>
  52.       <geoLocation>
  53.         <geogLocation xsi:type="LatLonPointType" srs="EPSG:26918">
  54.           <latitude>42.943528</latitude>
  55.           <longitude>-76.540317</longitude>
  56.         </geogLocation>
  57.       </geoLocation>
  58.       <note title="County">Cayuga</note>
  59.       <note title="State">New York</note>
  60.     </siteInfo>
  61.   </site>
  62. </sitesResponse>
  63.  
Code:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Collections;
  11. using System.IO;
  12. using System.Xml;
  13. using System.Xml.Serialization;
  14.  
  15. /// <summary>
  16. /// Summary description for ODMSiteList
  17. /// </summary>
  18. /// 
  19.  
  20.  
  21. [XmlRoot("sitesResponse", Namespace="http://www.cuahsi.org/waterML/1.0/")]
  22. public class ODMSiteList
  23. {
  24.     private ArrayList siteList;
  25.     public ODMSiteList()
  26.     {
  27.         siteList = new ArrayList();
  28.     }
  29.     [XmlElement("queryInfo")]
  30.     public ODMQueryInfo query = new ODMQueryInfo();
  31.     [XmlElement("site")]
  32.     public ODMSite[] sites
  33.     {
  34.         get
  35.         {
  36.             ODMSite[] sites = new ODMSite[siteList.Count];
  37.             siteList.CopyTo(sites);
  38.             return sites;
  39.         }
  40.         set
  41.         {
  42.             if (value == null) return;
  43.             ODMSite[] sites = (ODMSite[])value;
  44.             siteList.Clear();
  45.             foreach (ODMSite site in sites)
  46.                 siteList.Add(site);
  47.         }
  48.     }
  49.     public int AddItem(ODMSite site)
  50.     {
  51.         return siteList.Add(site);
  52.     }
  53. }
  54. public class ODMSite
  55. {
  56.     ArrayList siteInfoArrayList = new ArrayList();
  57.     [XmlElement("siteInfo")]
  58.     public ODMSiteInfo[] SiteInfoList
  59.     {
  60.         get
  61.         {
  62.             ODMSiteInfo[] SiteInfoList = new ODMSiteInfo[siteInfoArrayList.Count];
  63.             siteInfoArrayList.CopyTo(SiteInfoList);
  64.             return SiteInfoList;
  65.         }
  66.         set
  67.         {
  68.             if (value == null) return;
  69.             ODMSiteInfo[] SiteInfoList = (ODMSiteInfo[])value;
  70.             siteInfoArrayList.Clear();
  71.             foreach (ODMSiteInfo siteInfo in SiteInfoList)
  72.                 siteInfoArrayList.Add(siteInfo);
  73.         }
  74.  
  75.     }
  76.     public int AddItem(ODMSiteInfo site)
  77.     {
  78.         return siteInfoArrayList.Add(site);
  79.     }
  80.     public ODMSite()
  81.     {
  82.         siteInfoArrayList = new ArrayList();
  83.     }
  84. }
  85.  
  86. public class ODMSiteInfo
  87. {
  88.     [XmlElement("siteName")]
  89.     public string _SiteName;
  90.     public string SiteName
  91.     {
  92.         get { return _SiteName; }
  93.         set { _SiteName = value; }
  94.     }
  95.  
  96.     [XmlElement("siteCode")]
  97.     public string _SiteCode;
  98.     public string SiteCode
  99.     {
  100.         get { return _SiteCode; }
  101.         set { _SiteCode = value; }
  102.     }
  103.     [XmlElement("geoLocation")]
  104.     public ODMGeoLocation _OdmGeoLoc;
  105.     public ODMGeoLocation OdmGeoLoc
  106.     {
  107.         get { return _OdmGeoLoc; }
  108.         set { _OdmGeoLoc = value; }
  109.     }
  110.     [XmlElement("verticalDatum")]
  111.     public string _VerticalDatum;
  112.     public string VerticalDatum
  113.     {
  114.         get { return _VerticalDatum; }
  115.         set { _VerticalDatum = value; }
  116.     }
  117.  
  118.     public ODMNote[] note
  119.     {
  120.         get
  121.         {
  122.             ODMNote[] note = new ODMNote[_NoteArrayList.Count];
  123.             _NoteArrayList.CopyTo(note);
  124.             return note;
  125.         }
  126.         set
  127.         {
  128.             if (value == null) return;
  129.             ODMNote[] note = (ODMNote[])value;
  130.             _NoteArrayList.Clear();
  131.             foreach (ODMNote snote in note)
  132.                 _NoteArrayList.Add(snote);
  133.  
  134.         }
  135.     }
  136.     private ArrayList _NoteArrayList;
  137.  
  138.  
  139.     public ODMSiteInfo()
  140.     {
  141.         _NoteArrayList = new ArrayList();
  142.     }
  143.  
  144. }
  145. public class ODMGeoLocation
  146. {
  147.     private ArrayList locList;
  148.     [XmlElement("geogLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
  149.     public ODMGeogLocation[] ODMGeoLocations
  150.     {
  151.  
  152.         get
  153.         {
  154.             ODMGeogLocation[] GeogLocations = new ODMGeogLocation[locList.Count];
  155.             locList.CopyTo(GeogLocations);
  156.             return GeogLocations;
  157.         }
  158.         set
  159.         {
  160.             if (value == null) return;
  161.             ODMGeogLocation[] GeogLocations = (ODMGeogLocation[])value;
  162.             locList.Clear();
  163.             foreach (ODMGeogLocation loc in GeogLocations)
  164.                 locList.Add(loc);
  165.         }
  166.     }
  167.     public ODMGeoLocation()
  168.     {
  169.         locList = new ArrayList();
  170.     }
  171.  
  172. }
  173. public class ODMGeogLocation
  174. {
  175.     [XmlAttribute("type")]
  176.     public string _geogType;
  177.     public string geogType
  178.     {
  179.         get
  180.         {
  181.             return _geogType;
  182.         }
  183.         set
  184.         {
  185.             if (_geogType == value)
  186.                 return;
  187.             _geogType = value;
  188.         }
  189.     }
  190.  
  191.     [XmlAttribute("srs")]
  192.     public string _geogSrs;
  193.     public string geogSrs
  194.     {
  195.         get
  196.         {
  197.             return _geogSrs;
  198.         }
  199.         set
  200.         {
  201.             if (_geogSrs == value)
  202.                 return;
  203.             _geogSrs = value;
  204.         }
  205.     }
  206.     [XmlElement("latitude")]
  207.     public float _Latitude;
  208.     public float Latitude
  209.     {
  210.         get
  211.         {
  212.             return _Latitude;
  213.         }
  214.         set
  215.         {
  216.             if (_Latitude == value)
  217.                 return;
  218.             _Latitude = value;
  219.         }
  220.  
  221.     }
  222.  
  223.  
  224.     [XmlElement("longitude")]
  225.     public float _Longitude;
  226.     public float Longitude
  227.     {
  228.         get
  229.         {
  230.             return _Longitude;
  231.         }
  232.         set
  233.         {
  234.             if (_Longitude == value)
  235.                 return;
  236.             _Longitude = value;
  237.         }
  238.     }
  239.  
  240.     public ODMGeogLocation()
  241.     {
  242.  
  243.     }
  244. }
  245. public class ODMNote
  246. {
  247.     [XmlAttribute("title")]
  248.     public string title;
  249.     [XmlElement("note")]
  250.     public string note;
  251.     public ODMNote()
  252.     {
  253.  
  254.     }
  255. }
  256. public class ODMQueryInfo
  257. {
  258.     [XmlElement("criteria")]
  259.     public string criteria = string.Empty;
  260.     public ODMQueryInfo()
  261.     {
  262.  
  263.     }
  264. }
  265.  
Please send help :)
Oct 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: peter | last post by:
In run-time,is there any approach to add or revise the members,such as method or attribute ,of a class or object? As for the object of class soapclient30 in MS soap toolkit, after it executes the...
2
by: Krish | last post by:
Hi, I have a question, if I have a global function that pointed to class or object, then how do I pass arguments to that function. I have CService *MyService; in my cpp and in my header, i have...
2
by: peter | last post by:
In run-time,is there any approach to add or revise the members,such as method or attribute ,of a class or object? As for the object of class soapclient30 in MS soap toolkit, after it executes the...
3
by: Eric | last post by:
I need to send an object between nodes on a network. Each node currently communicates fine with sending strings around but I can't figure out how to deserialize objects using the same basic...
1
by: peter | last post by:
In run-time,is there any approach to add or revise the members,such as method or attribute ,of a class or object? As for the object of class soapclient30 in MS soap toolkit, after it executes the...
0
by: Matt S | last post by:
Hello, I'm trying to build a C# client to consume an AXIS Web Service (running SOAP over HTTP). The Web Service encodes full server-side exception traces in the Soap Fault > Detail element...
6
by: Val | last post by:
How can I serialize/deserialize an object into a string. Existing examples seem to be showing this operation for files only. Thansk
6
by: kasper.rung | last post by:
I am having trouble implementing an interface. The interface requires a method to return an object, but it does not seem to be able to treat a reference type as an object. I have the following...
3
by: Matrixinline | last post by:
Hi All, I know I am asking a dumb question but can you Please let me know what should be the size of the class & its object? will the Objects size will be different? class Product {...
14
by: =?GB2312?B?zPC5zw==?= | last post by:
Howdy, I wonder why below does not work. a = object() a.b = 1 # dynamic bind attribute failed... To make it correct, we have to create a new class: class MyClass(object): pass a =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.