Having trouble making a class that serialises how I want..

Hi All

I devised an XSD schema for a service offered by a remote company (on
a very simplistic level) and used the XSD.EXE to turn it into a suite
of classes, the idea being that I can make a library out of them to
give to other developers, and the other dvelopers will simply say:

service.Address.FirstLine = "1 The Road"
service.Address.ZIPCode = "12345"
service.Person.Name = "John Smith"
socket.WriteString(service.ToXML() )

Or something like this. Now my problem comes when some elements may
appear more than once. I was given to understand that I must thus put
them in an array but its the presence of the array that is giving
difficulty

A person has a Current and a Previous address. Irritatingly, the only
thing that differentiates the two is the order they appea rin the XML
document. I told the company we are dealing with that relying on order
to give meaning to data is not what XML is about, and I wasnt
impressed with their refusal to do anything about it, but that's the
end of that.. I must now work with those constraints

So, I'm trying to generate some xml like this (i've left data out,
just putting empty tags for simplicity):

[code]
<root>
  <address>
    <firstline/>
    <zipcode/>
  </address>
  <address>
    <firstline/>
    <zipcode/>
  </address>
  <person>
    <name/>
  </person>
</root>
[/code]

Of concern is the address.. It is to be such that the first block of
address is the current address. the previous address comes in the
second address tag




My code in VB.NET (i can translate to C# if required) looks something
like:




[System.Xml.Serialization.XmlArray("address")]
Public addresses(0 to 1) as New AddressXMLBlockRepresentation

[System.Xml.Serialization.XmlIgnore()]
Public Property CurrentAddress
  Get
    Return addresses(0)
  End Get
  Set
    addresses(0) = value
  End Set
End Property

[System.Xml.Serialization.XmlIgnore()]
Public Property PreviousAddress
  Get
    Return addresses(1)
  End Get
  Set
    addresses(1) = value
  End Set
End Property




So, i've set an ignore for the two properties so i dont get XML
looking like:
<CurrentAddress>
  <address>
    <firstline/>
....
</CurrentAddress>
<PreviousAddress>
  ...
</PreviousAddress>




But now i'm finding that the XML forms like::


<root>
  <AddressXMLBlockRepresentation>
    <address>
      <firstline/>
      <zipcode/>
    </address>
    <address>
      <firstline/>
      <zipcode/>
    </address>
  </AddressXMLBlockRepresentation>
  <person>
    <name/>
  </person>
</root>
[/code]



Anyone know how to get the array to serialise out as a sequence of
elements <address> without the enclosing type name being in there too?

I did try setting an IGNORE on the array and saying each Property must
have a
[System.Xml.Serialization.XmlElement("address")]

But it errors on reflecting - "address" appears twice (understandable
- this couldnt be deserialized if one tag name could refer to two
properties)

This must be possible because DataSet already does this.. If we
serialize a dataset containing one datatable, that has 4 rows we get:

<DataSet1 xmlns="http://tempuri.org/DataSet1.xsd">
  <DataTable1>
    <Column1>1</Column1>
  </DataTable1>
  <DataTable1>
    <Column1>2</Column1>
  </DataTable1>
  <DataTable1>
    <Column1>3</Column1>
  </DataTable1>
  <DataTable1>
    <Column1>4</Column1>
  </DataTable1>
</DataSet1>

I want my address to be the equivalent of the DataTable1 nesting
level, and the elements an address contains be the equivalent of the
Columns but I dont know how to do that..

Also, of further nuisance, the serializer will only serialize public
fields, which means my array has to be public, which means it can be
seen by other coders. The idea was to develop a library that worked
with intellisense so that developers wouldnt see the internal array
name when they type the service name followed by period..

0
mcw8 (1)
8/25/2007 8:35:14 AM
dotnet.xml 7266 articles. 0 followers. Follow

0 Replies
443 Views

Similar Articles

[PageSpeed] 21

Reply:

Similar Artilces:

Email trouble with New User in Active Directory
Below is a trail of posts that have been made. My problem has yet to resolved and I need some help quickly. The only other thing I can think of is to reinstall Exchange Server 2003. Hopefully someone will know the answer. Thanks! Subject: Re: Email not Setup when new user created in Active Directory From: "Bryan Hill" <bthill@comcast.net> Sent: 8/15/2004 12:30:21 PM We have other clients that are working fine. Just when we try to set up new ones - it will create the SMTP address but not the X400 address. I tried manually forcing the X400 but it will...

I want to disable the auto hyperlink feature.
I have a spreadsheet with lots of hyperlink-like data (but that are not actually hyperlinks) that is edited frequently. It is very frustrating when excel decides to auto-format the data into a hyperlink, especially because right clicking on it and picking "remove hyperlink" also removes ALL formatting for that cell. How can I disable the auto hyperlink feature? (I already searched the forum and there are other messages which looked hopeful but the threads cannot be displayed) You can type an apostrophe at the start of the entry, and Excel won't create a hyperlink. For example...

how can i make furmulas for converting gram to microliter,thanks
please help me to find how i can convert gram to microliter What kind of Liquid are we dealing with !? Micky "aedrion" wrote: > please help me to find how i can convert gram to microliter Hi aedrion, There is no direct conversion - grams are units of mass (weight); microlitres are units of volume. If, of course, you know how many microlitres of a substance weighs 1 gram, then you can do the conversion for that substance. -- Cheers macropod [Microsoft MVP - Word] "aedrion" <aedrion@discussions.microsoft.com> wrote in message news:CDE712...

Trouble with the template.
I want to reset the 'normal' template to default to "Times New Roman" 10point font, and the pages numbered centre top. This seems to work when I set and reopen Word2003 from the Administrator Template vis: C:\Documents and Settings\Administrator\Application Data\Microsoft\Templates. But it will not work when I open Word2003 normally from the desktop. I have deleted the "Normal.dot" from the following and copied in the "Normal.dot" from the Administrator above: C:\Documents and Settings\All Users\Application Data\Microsoft\Templates...

everything wants to connect to net
I've been happily running Outlook 2002 for a year or more. Recently uploaded activsynd and reinstalled Outlook 2002 with my new pda (ipaq h2210). Now everything seems to want to connect to the net and it didn't before. I don't have broadband so, this is irritating. Can I stop that happening? Martin ...

How to make a cell display a minimum value
Hi I have a very simple spreadsheet that works the total area of a piece of glass. Similar to this Width Height Area Where Area = Width*Height I want to make it so that the Area cell will display a minimum value if a certain value is too low. For instance .478*.456 is actually equal to 0.217, but I want to make the minimum area 0.30. this makes it that any value that is returned in the Area cell must be a minimum of 0.30. Anything over 0.30 is OK. I would assume that a command similar to this would suffice If C3 < 0.30 then Let C3 =.30 But, where do I type this? Can anyon...

making a pivot from an other pivot
Hey guys i need to make a pivot on data that is already returned by a pivot chart in Excel 2000 do you have any refences i could look at ? I am looking at the static approche but i will eventualy be doing it using vba... Regards, Alexandre Brisebois You can record a macro as you create a pivot table, and select 'Another PivotTable report' as the source in step 1. Alexandre wrote: > Hey guys i need to make a pivot on data that is already returned by a > pivot chart in Excel 2000 > > do you have any refences i could look at ? > > I am looking at the static appr...

Outlook wants me to save changes to normal.dot
Whenever I exit Outlook 2003 after using Word to write or edit messages I am prompted to save changes to normal.dot, even when I just open the new message window and close it straight away without typing any text. I've gone through the knowledge base without finding any relevant fixes - no virus found by Norton, no add-ins or macros and my office 2003 startup folder is empty. My easy fix has always been to go back to using HTML instead of Word, but miss the functionality of tables and other Word features. There is a word addin that causes it - if you have acrobat it's addin ...

Making A Databse system on Excel?
Ok, I need to be able to save any information that is entered onto a sheet on another sheet, but I need the sheet where the information is entered to stay blank and then just enter information and it saves onto the other sheet, so I get a database system. How would I do this? L, You could do it using a macro, either run manually or automatically. For example, this will move Row 2 of Sheet1 to the bottom of the set of data on Sheet2. Assumes that cells in column A are never blank. Sub MoveEmOut() Worksheets("Sheet1").Range("2:2").Cut Worksheets("Sheet2").R...

trouble with CrmIsapi.dll
I was experiencing the same problem with the SDK as many have posted to this group ... "the WhoAmI() call results in a http error 405 when running sample code" I followed some of the advice; checked my .srf mapping to CrmIsapi.dll and re-registered the CrmIsapi.dll. when I re-register CrmIsapi.dll I get an error 80004005 - unspecified. ??? I copied it to various places and retried it ... same result. I got the original from the disk and retried ... same result. unmapped it from .srf, restarted and retried to register it ... same result. Anyone experienced this. What's up with m...

how do I make multiple pie charts at the same time?
I have multiple lines of data and I want to make multiple pie charts (over 50) at the same time by simply going down the row and creating a pie chart with each row. I can't figure out a macro on how to do it, and simply copying and pasting and then deleting a series resets all of my formatting preferences! A long time ago (nearly 5 years!) I posted this macro that makes a pie for each row in the data range. The data is in A:E, with the category labels in A1:E1 and the values in each row below that. The charts are overlapped ot the right of the data. Sub LotsaPies() ' Macro ...

how to make the content of a listbox to be copyalbe
hi, could you tell me how to make the contents of a listbox to be copyable. thank you ...

Trouble with Outlook 2003 and PST File
Hi, We have a user who is using Outlook 2003 and moves most emails to a PST file which is considered archived email data. They have reached the Max limited on this PST file of 1.99GBs and its not letting them open the PST file. It is trying to repair it when they try to open the PST file. Here is the message they receive: "Can't move the items. The file <path>\<filename>.pst has reached its maximum size. To reduce the amount of data in this file, select some items that you no longer need, and then permanently delete them." I can't even get it open to delete...

unexpected conversion trouble
I wanted to open an Excel file I hadn't been working on for a while, an Excel couldn't do it. After some investigations, I found that even if the file still had th .xls extension, it seemed to be conveted in .doc format (in fact, whe I open it in notepad, I can see at the end some words that look like MSWord signature). I don't know how this happened, but I'm reall embarassed beacause i really need the data in this file. I tried to change the extension to .doc, open the file in Word and the import in Excel, but I can hardly see part of the file. What's more, i is a 3-she...

How do I make a commandbar control bold?
I've added a commandbar control to the right click menu. Does anyone know how I can make it bold? Any help would be appreciated. Thanks I don't believe you can change Font attributes of a commandbar control. If it's really important to you (I wouldn't like it) maybe make a bitmap of your bold text and add that as the ButtonIcon. Regards, Peter T "josh" <josh@discussions.microsoft.com> wrote in message news:12B873FD-9F4D-4879-BA80-99EF0990BE86@microsoft.com... > I've added a commandbar control to the right click menu. Does anyone kn...

Make booklet
I want to create a booklet for our 40th year class reunion. How do I set this up in Publisher? Help would be greatly appreciated! File - New. After you choose either a blank page or a template, File - Page Setup and choose booklet -- JoAnn Paules MVP Microsoft [Publisher] "Susanne Sanders" <Susanne Sanders@discussions.microsoft.com> wrote in message news:497340EA-C144-4BEB-839F-CDBDF84CE60F@microsoft.com... >I want to create a booklet for our 40th year class reunion. How do I set > this up in Publisher? Help would be greatly appreciated! Thank you very ...

I am in trouble
Hi, I am a student in Cambodia.I don't have any girlfriend. I tried everything. I looked at them wrote poem to them it doesnt work. I got an account from facebook, hi5 friendster myspace. I have 0 girl friend. What should I do? I am so desperate. I am good looking and 250 kg only. Please help me or at least send me some foood I am hungry Best Regards Hungry Guy __________ Information from ESET NOD32 Antivirus, version of virus signature database 4944 (20100314) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com You're tr...

Trouble with Pivot Tables & Named Ranges
Can I use a dynamic named range setup in one file as a range in pivot tables in another file? When I have the data source file (with the named range) and the pivot report files open, the pivot reports update just fine. But the moment I close the source data, the pivot reports no longer can update and I get a message that the source can't be found. If I reopen the source, the pivot tables work fine again - but as soon as I close it up, the reports no longer work. The source file is very large and I don't want to open it every time I have to update all the reports tha...

How to make variables public
On the main form are several control buttons that open different forms that then open other forms and reports. All this works fine. But I would like to declare an array of string that would be available to all forms and report alike. The reason is if I change the name of a product I don't have to go through all of the code to change strings all over the place and for sure I will forget one. To do that I added a class module and put this in it : Option Compare Database Const nb_prod As Long = 6 ' Nb de produit disponible Dim lst_produit(6) A...

Trouble with "time" in formulas
I have a time sheet that looks something like this: A1=time...A2=time...A3=A2-A1+if(A1/24,1)...A4=if(or(A3<time(0,15,0),A3>time(4,0,0)),A3,time(4,0,0)) A1 and A2 are set up as dropdown lists and the times in the list are i increments of 15 minutes. WHat I'm trying to accomplish is (in cell A4 if A3 is between 15 minutes and 4 hours, then return 4 hours. if A3 i 0 or greater than 4 hours, return A3. If I enter enter times in A1 around 00:00 and A2 a little after 00:0 it works fine... example: A1=22:00...A2=01:00...A3=03:00...A4=04:00 A1=20:30...A2=00:15...A3=03:45...A4=04:00 A1=00...

trouble
I have been using my MS Publisher 2000 for over 3 years. Just recently I attempted to access the Publisher program and got the following message: "This application must be installed to run. Please run setup fom the location where you originally installed the application." I have done everything I know to fix this including uninstalling and reinstalling the program. I don't understand what happened overnight nor do I understand the instruction "run from the location you originally installed the program". I can not access the numerous publicaions that I have cr...

Trouble sorting a table???
Using Excel 2002) I am relatively new to Excel and can only really perform simple functions in a basic spreadsheet. The spreadsheet I'm having trouble with is pretty basic, but I'm having trouble sorting some of the results from a table. (I'll try and explain as best as I can) I have 10 people that I'm tracking 5 different things for (dates, debts, credits, items, number of transactions, and their balance as calculated in this table by simple SUM functions) I then have another table with these same 10 people with their total balance. This is the table I'm having t...

Having trouble
I have a set of numbers, a-e. A usually equals e but can be less. B remains constant. C is the sum of A and B. C cannot exceed D. D remains constant I have tried the following formula in the box for A, but C ends up being less than D when I want it to equal D =IF(C>D,E-(C-D)) What am I doing wrong? Uhh, I'm a little slow, but; If you are putting this formula in A and it's the same "A" that is part of the "C=Sum A & B" then I think you have a circular reference. In other words, you're asking xl to resolve "A" by asking "If C> D&quo...

Make all dates display 01 as the day
I have a list of dates with various numbers listed as the day (03/25/2009, 04/05/2010, etc.) I need a formula to change all of the dates to display 01 as the day (03/01/2009, 04/01/2010, etc). Thanks! -- LL28 First date in A1 (03/25/2009) In B1 =DATE(YEAR(A1),MONTH(A1),1) will display 01/05/2009 best wishes -- Bernard Liengme Microsoft Excel MVP http://people.stfx.ca/bliengme "LovingLife28" <LovingLife28@discussions.microsoft.com> wrote in message news:FDFA5015-6DF0-4374-842F-C8DA14E9952F@microsoft.com... > I have a list of dates with various number...

Cancellations are being sent for meetings that I do not want cancelled
I have been experiencing some issues with the updating of recurring meetings that I have set up. Some of people have noted that when I send out an update to a meeting, they receive an update notice and then a cancellation immediately right after. This action removes the meeting from their calendars and the update cannot be applied. This only happens when I use Outllok 2003; if I use Outlook 2000 or Outlook XP the cancellations do not go out automatically. Please help. ...