Deserialization with CollectionBase and attribute on root element

I've got a simple XML document (from an external source that I can't change) 
that I'm having trouble deserializing correctly.

The document looks like:

<?xml version='1.0'?>
<quotes timestamp="17:49:23">
    <quote id="0" value="foo"/>
    <quote id="1" value="bar"/>
</quotes>

I've defined a class "quotes" derived from CollectionBase and all of my 
deserialization is working fine except that I can't figurout how to 
deserialize the "timestamp" attribute on the root "quotes" element.

Here's what I've got:

[XmlRootAttribute("quotes")]
public class quotes : CollectionBase
{
    [XmlAttribute("timestamp")]
    public string timestamp;

    public virtual void Add(quote NewQuote)
    {
       this.List.Add(NewQuote);
    }

    public virtual quote this[int index]
    {
    get
    {
        return (quote)this.List[index];
    }
}


To deserialize, I get a HttpWebResponse stream and then deserialize it, 
nothing fancy:

....
  requestStream = HTTPResp.GetResponseStream();
  myQuotes = (quotes)xs.Deserialize(requestStream);

....


When I look at the resulting MyQuotes, the individual "quote" objects in the 
collection have deserialized correctly, but MyQuotes.timestamp is null, even 
though there was a value for it in the source XML document.

I've seen tons of examples of how to deserialize using CollectionBase, but I 
have not yet seen an example that has an attribute value on the root 
element.

Any ideas? 


0
1/8/2006 7:47:19 PM
dotnet.xml 7266 articles. 0 followers. Follow

0 Replies
486 Views

Similar Articles

[PageSpeed] 19

Reply:

Similar Artilces:

XmlSchemaValidator and XmlSerializer.Deserialize()
In an application which uses an XML file, I wish to use XmlSchemaValidator class to validate this file against the XSD file.. In the example of msdn, ( http://msdn2.microsoft.com/en-us/library/system.xml.schema.xmlschemavalidator(VS.80).aspx ) , before initialising the XmlSchemaValidator, XmlSerializer is initialised. I saw that if there is a node or attribute which is not valid (to xml schema), the method XmlSerializer.Deserialize() launches an exception. It means that before validating this file ( or stream ) its already controlled by Deserialize method. I wish to know what is the n...

CRM 1.2 unable to add users in OU but domain root OK.
Hello. I am having trouble adding users to CRM 1.2. If I try to add a CRM user from an OU in the domain with deployment manager or the web GUI it fails. If I add a user to CRM from the root of the domain the user is added fine to CRM. In our test environment I was able to add users to CRM that are in OU's in a test domain without any trouble. Any ideas? Thanks!! Mike ...

attribute display names
I am trying to find the corresponding display names for each attribute. I have a case where the schema names and the actual CRM field names are very different. I want to put a spreadsheet together with the field name from the form and its actual database name. Which table holds the display name? I have looked in the metabase and have not found it yet. Thanks, Ryan See the StringMap table in the MSCRM DB. HTH, Dave Ryan wrote: > I am trying to find the corresponding display names for each attribute. I > have a case where the schema names and the actual CRM field names are ver...

XML Deserialization
Hello Guys, I have tried to use the xsd.exe tool to generate a class for the following Oracle-generated xml sample but always fail to get it right when I try to change oracle xml elements names to the class's names, specifically I'm not sure how to do it for the ROWSET and ROW part of it. Being very new to the serialization/deserialization business I'm sure this is very easy to implement for someone with a bit of more knowledge of it, can some help me please. I have created 2 classes for for Department and Employee: [XmlRoot("ROWSET")] class Dep...

MS Publisher window element
I have been using MS Publisher 2007. When you go into the main window after choosing a template from the launch window, the task panes appear and you have a space for the work area. This is the region of the publisher window, where the pages of the publication are displayed. You also have a scratch area where you place Objects before placing them into the publication. I want to know what do you call this work area in the main Publisher window. Is there a term for it? If there is none appears in the Publisher help. Thank you Aarthi P.S. Please clarify the name of teh main window taht a...

C#: How to deserialize an object to a string
I want to know how can i deserialize an object to a string, instead of a file as below:ShoppingList myList = new ShoppingList(); myList.AddItem( new Item( "eggs",1.49 ) ); myList.AddItem( new Item( "ground beef",3.69 ) ); myList.AddItem( new Item( "bread",0.89 ) ); // Serialization XmlSerializer s = new XmlSerializer( typeof( ShoppingList ) ); TextWriter w = new StreamWriter( @"c:\list.xml" ); s.Serialize( w, myList ); w.Close(); // Deserialization ShoppingList newList; TextReader r = new StreamReader( "list.xml" ); newList = (ShoppingList)s....

deserializing
I'm trying to deserialize my xml type as an array w/o a declared namespace, but none of the Serialization Attribute classes help. Where can I find info on how to build a deserializer that will create arrays? I think you will need to create a wrapper class and suck the array out of that wrapper. "jsh02_nova@hotmail.com" <jsh02novahotmailcom@discussions.microsoft.com> wrote in message news:89A83E5F-EC8D-4EB2-A737-5FFF86FCCC14@microsoft.com... > I'm trying to deserialize my xml type as an array w/o a declared > namespace, > but none of the Serialization Att...

Serialization
I am serializing a class I have and do not want any attributes in the root. Here is what I have so far. [System.Xml.Serialization.XmlRootAttribute("configuration", Namespace="", IsNullable=false )] public class ShoppingList { .... } which yields this <?xml version="1.0" encoding="utf-8" ?> - <configuration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> How do I get rid of the "xmlns:xsd" and the "xmlns:xsi". Also, I would like to get rid of the ...

ScanPst have run time attributes?
Does ScanPST have attributes you can put after scanpst.exe. Such as file to scan and to run repair automatically after detection finishes, without having to hit enter. My PST is large and would like to have it run during the night. Nope. The program takes no command line parameters or switches and requires the user to enter the name of the .pst file that requires "fixing". There is at least one commercial alternative, "Advanced Outlook Repair" by DataNumen, Inc. I have no experience with this product but it advertises that it supports command line parameter...

XML Deserialization Issue
Hello All, I am having some trouble deserializing some xml into a series of objects that are part of a web service proxy. I know the XML is valid, and the objects are up to date (the xml instance doc validates against the original scheme, which is current with the WSDL). The issue looks familiar, its identical to one that I have seen when the xmlserializer chokes on a namespace. In past instances with simple XML docs I was able to get things working by supplying the Deserialize method a default namespace, but in this case I have 3 namespaces, and no default. Any ideas as to how I would go ...

Deserialization
I have an xml file containing some stuff. I use xsd to generate a schema and again to create classes from the schemas. added using System, System.IO; added [Serializable] to all classes added namespace ROC added deserialize() method as follows to AWLR2 class: public AWLR2 deserialize(string xmlString) { AWLR2 awlr2; try { StringReader sr = new StringReader(xmlString); XmlSerializer ser = new XmlSerializer(this.GetType()); awlr2=(AWLR2)ser.Deserialize(sr); } catch(Exception ex) { System.Diagnostics.EventLog.WriteEntry("BizTalk Redemptions", ex.ToString()); throw ex; } ...

How to get elements from XML using DOM in Javascript
I am getting an error... elem is null or not an object using the following Client side javascript. Can someone give me some help? Thanks in advance. <XML ID="PB"> <ProductItem> <Product ID="Adhesive"> <ItemType>Machine</ItemType> </Product> </ProductItem> </XML> <script language=javascript> var root = new ActiveXObject("Microsoft.XMLDOM") var xmldoc = new ActiveXObject("Microsoft.XMLDOM") xmldoc.async = false; xmldoc = document.getElementById("PB"...

Query file-attributes over the internet
Hello, My program (VC++ 6.0) is reading a large html file, which is located at a web hotel, to check if the file has been updated since the last time it was checked (by comparing the file with a local backup). To save a lot internet trafic, I would like the program to query the file's attributes and thus determine if the date of the last update has changed. Is there a way to do this? Hello, As I recall, you can request the file's header only and you will get a "Last-Modified" entry, you can check this header and compare its date with your local document date. Regards, E...

How to deserialize with several namespaces
Hello, I'm trying to deserialize an RSS feed that can contains 2 namespaces. FOr example, it can contain a tag <image> and/or <itunes:images>. I couldn't figure out how to get both. This simplified extract of code does not work: [XmlRoot(ElementName = "rss")] public class RSSFeed { [...] [XmlElement("image", typeof(Image))] public Image Picture = new Image(); [XmlElement("image", typeof(Image), Namespace="http://www.itunes.com/dtds/podcast-1.0.dtd")] public Image iPicture = new Image(); public RSSFeed Load(Strea...

finding attributes of the folder in the network
How to find attributes of the folder in the network using C++/ VC++ I want to check whether the folder has got write permissions or not....... Take a look at GetFileSecurity: http://msdn2.microsoft.com/en-us/library/aa446639(VS.85).aspx --- Ajay <mak.raut@gmail.com> wrote in message news:d3cc1425-ef6c-49da-866e-28013affa711@u10g2000prn.googlegroups.com... > How to find attributes of the folder in the network using C++/ VC++ > I want to check whether the folder has got write permissions or > not....... > ...

Deserialize xml
Hi, I am getting an error when I try to deserialize a XML file into a object with a apostrpohe in the data. Works fine when I remove the apostrophe. Any thoughts???? Rotsey wrote: > Hi, > > I am getting an error when I try to deserialize a XML file into a object > with a > apostrpohe in the data. > > Works fine when I remove the apostrophe. > > Any thoughts???? Can you specify error details, code snippet and some sample data for which you are getting error ? ...

How do I change default attribute values from with in SQL Metabase
I need to change a bunch of bit defaults from yes to no and was hoping to do it from within Enterprise Manager quickly instead of going in and out of every field withing CRM. Anyone know the table I need to look at where this is stored? I looked at the attribute table in the metabase which seems to have a column called default value but this does not store the default as I looked at default settings of two bit fields I have one set to yes and one set to no and in the attribute table there is no difference that I can see. -- Thanks, Brian Updating the tables on the back end is not supp...

XMLDocument
This is a multi-part message in MIME format. ------=_NextPart_000_0016_01C70CB3.46F04820 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm using the followg code to add the attribute overwrite=3D'true" to a = select list of XML tags in an XML document. The document is loaded from = a file and just the tags with names matching what's in the ArrayList are = updated to contain the new attribute. However, after it saves back to = the XML file, I find that only the last one in the list was updated and = all the ones prior ...

Deserialize Attribute with a Namespace
I have an xml document like so... <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:ng="http://newsgator.com/schema/extensions"> <channel> <title></title> <link></link> <description></description> ... </channel> </rss> What .NET XmlAttribute properties do I need to use in order to deserialize the namespace value? I tried this and a bunch of other options, but nothing seems to work. [XmlAttribute("ng", "http://newsgator.com/schema/exten...

"The 'maxoccurs' attribute is not supported in this context"
Hi, I'm trying to load some XML into a dataset with C# but I have an issue with the schema. I'm using exactly the same code to successfully load other XML. The only difference is in the XML I'm trying to load it has: xs:choice maxoccurs="unbounded" The error message I'm getting is: "The 'maxoccurs' attribute is not supported in this context" The code I'm using to load the DataSet is: WebRequest request = WebRequest.Create(SchemaURL); request.Proxy = new WebProxy(proxyServer); request.Proxy.Credentials = credentials; HttpWebResponse re...

mail enabling root public folder
Hi, how can I assign an e-mail address to the folder which shows on clicking the Public Folders in Outlook? Right click the public folder in ESM, 'mail enable' Then click on the email address tab and assign SMTP addresses. Oliver On Tue, 27 Feb 2007 14:09:52 +0100, "Jan Kucera" <miloush@community.nospam> wrote: >Hi, how can I assign an e-mail address to the folder which shows on clicking >the Public Folders in Outlook? You can't. Why would you want to? :) Hi, Re-reading your question. You can't mail enable Folders | Public Folders This is...

Attribute Event
Can anyone share what is wrong with the following event script? MethodOfService is a drop-down field, and I'm wanting to populate the visual values into Subject. crmForm.all.subject.DataValue = switch(crmForm.all.new_methodofservice.DataValue) {case 1: "Remote Access" break; case 2: "Web Session w/Client" break; case 4: "Off-Site" break; case 5: "On-Site" break; case 6: "EMail Only" break; case 3: "Phone Call Only" break; default: "Other"}; Hi Cindy, the switch statement does not return a value thus the assignmen...

Force the prefix of the document element
Hi, I have an XmlDocument loaded from a memory stream. I set the document element prefix in this way XmlElement e = xDoc.DocumentElement; e.Prefix = "abc" When i simply write the document element to the command line it shows the prefix. However, it does not persist in the XmlDoc so when i save the XmlDoc into a file, the prefix is no longer there. Can anyone help? I need to sort this out rather urgently. Thanks, Benjy BizTalk Benjamin wrote: > Hi, I have an XmlDocument loaded from a memory stream. I set the document > element prefix in this way > > XmlElemen...

CObArray with huge number of elements
Hope someone can help I need to hold potentially huge numbers of CObject pointers in an array As a simple test I tried this... CObject *this = new MyObject(); CObArray things; for (long y=0;y<1000000;y++) things.Add(object); // just add the same one repeatedly this gets progressivly slower until it grings to a halt at about 200,000 elements If i try this CObject *this = new MyObject(); CObArray things; things.SetSize(1000000); // set the size before hand for (long y=0;y<1000000;y++) things[y]=object; this goes like the clappers - no problem except I...

XML deserializer
(Type your message here) -------------------------------- From: Rohit All, I have an xml that does not have any namespace associated with= any of the nodes but the element in the corresponding class= which has been generated using XSDObjectGen=2Eexe has= namespaces=2ESo after deserializing the XML to the class object,= my class object does not have any items in it=2E ----------------------- Posted by a user from =2ENET 247 (http://www=2Edotnet247=2Ecom/) <Id>sknZU2tYjEuSn48n2yL3ig=3D=3D</Id> ...