Formatting XmlSerializer Output

I'm using classes generated from xsd.exe.  I am serializing them with
XmlTextWriter, and everything works fine.  Our customer, though, has a
silly requirement that dollar amounts (in the .xsd as decimals) be
formatted to always include cents (regardless if there are cents or
not).  I'm interested in using the classes to only output data (i.e.
I'm not parsing incoming data)

I've tried setting up the following construct to format the output of
each of the affected decimal fields, but I don't get anything written
out to the .xml file.  What am I missing - and is there a better way?

    /// Override for Amount output
	[System.Xml.Serialization.XmlAttributeAttribute(AttributeName =
"Amount", DataType="string")]
	public string AmountString {
		get {
			return string.Format("#0.00", this.amountField);
		}
	}

	[System.Xml.Serialization.XmlIgnore()]
    public decimal Amount {
        get {
            return this.amountField;
        }
        set {
            this.amountField = value;
        }
0
12/14/2007 8:11:21 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
635 Views

Similar Articles

[PageSpeed] 34

<jasonterando@yahoo.com> wrote in message 
news:9e4d5fa2-643a-4405-a61c-9899a7c25082@e25g2000prg.googlegroups.com...
> I'm using classes generated from xsd.exe.  I am serializing them with
> XmlTextWriter, and everything works fine.  Our customer, though, has a
> silly requirement that dollar amounts (in the .xsd as decimals) be
> formatted to always include cents (regardless if there are cents or
> not).  I'm interested in using the classes to only output data (i.e.
> I'm not parsing incoming data)
>
> I've tried setting up the following construct to format the output of
> each of the affected decimal fields, but I don't get anything written
> out to the .xml file.  What am I missing - and is there a better way?
>
>    /// Override for Amount output
> [System.Xml.Serialization.XmlAttributeAttribute(AttributeName =
> "Amount", DataType="string")]
> public string AmountString {
> get {
> return string.Format("#0.00", this.amountField);
> }
> }
>
> [System.Xml.Serialization.XmlIgnore()]
>    public decimal Amount {
>        get {
>            return this.amountField;
>        }
>        set {
>            this.amountField = value;
>        }

Xml serialisation does not serialise read only properties. You can put in a 
set method for AmountString and get it to throw an error if used. Not ideal, 
I know.
The only other option I can think of is to implement IXmlSerializable and 
take control of the whole process.

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name 

0
12/16/2007 11:18:20 AM
Reply:

Similar Artilces:

Can I format mailing labels in Excel 2000?
-- The Hammer thanks you for the help! It's lots easier if you use excel to hold your data and MSWord to print: Here are a couple of links: http://www.mvps.org/dmcritchie/excel/mailmerg.htm http://www.mvps.org/word/FAQs/MailMerge The first is from David McRitchie and the second is by Beth Melton and Dave Rado. Mark H wrote: > > -- > The Hammer thanks you for the help! -- Dave Peterson ...

Pivot / general chart formatting question
Hi I'm writing some code to preserve the formatting of a couple of pivot charts (one stacked bar and one pie) using Excel XP. I found reference to the fact formatting is reset when the pivot is recalculated etc. (http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q215904), not a very usefull article by the way. Just tells us to write some code. Anyway... I am able to reference and format various series by name in the bar charts, but in the pie chart, if I record a macro the fomatting is associated with a point within the series. I need to be able to reference the points by na...

Using XmlDocument.Save removes previous formatting of the file
Hi all, I have a nicely formatted .xml file that loses that nice formatting when I edit it and use XmlDocument.Save to save the file. Does anyone know of any way to keep the formatting I had when I opened the file? Thanks! Aaron Sellers Hi Aaron, The XmlDocument.PreserveWhitespace property is what you need. Set it to True before Loading the XML document, and all whitespace is preserved. Set it to True before Saving, and your whitespace will be preserved. BTW, "XmlDocument.Save" auto-indents the output which you save. HTH, Regards, Cerebrus. Thanks so much, Cerebrus...

locate duplicates by sing conditional formatting--doesn't work for
Anybody have an idea why I get an error message "Cannot use conditional formatting for arrays...constants..." when I try to set up the conditional formatting in the first cell in the row I'll be searching for duplicate entries? I am following step by step the MS Assistance article's instructions for finding duplicates using the COUNTIF function. Perhaps there's a work-around or another way to find duplicate data within cells in a row (not duplicate records , though). Thanks. Post the formula that gives you the error -- Regards, Peo Sjoblom (No private emails pl...

cell format #3
When I enter a whole number (i.e. - 1, 2) into a cell, the result is a percentage (i.e. - .01, .02). I have reset the format to number, with no success. Tools > Options > Edit > clear the fixed decimal checkbox -- Gary''s Student - gsnu200773 Sounds like you have got Fixed Decimals turned on - this lets you type 12345 and get 123.56 (for lazy bookkeepers) Use Tools | Options; open the Edit tab; uncheck the Fixed Decimal option box best wished -- Bernard V Liengme Microsoft Excel MVP http://people.stfx.ca/bliengme remove caps from email "chris" <chris@disc...

Date format question #2
There is a date format that will format a date like this: "Wednesday, April 09, 2008" Can i create a custom format that will do this: Wed, Apr 09 If so, can you tell me how? Thanks, tom Select the cell, press Ctrl+1, select the number tab, select custom and type in: ddd, mmm dd Tyro "TomCon" <someone@verizon.net> wrote in message news:2ifGj.7437$Kw2.2142@trndny05... > There is a date format that will format a date like this: > "Wednesday, April 09, 2008" > Can i create a custom format that will do this: > Wed, Apr 09 > > If so, can...

html format of mailto mails
Hi Freinds, If I use <a href="mailto:pashour@mail.all-in-1.com?subject=test&amp;body=body">mailme</a > then how can I specify they type of email as HTML? Thanks in advance, Pat ...

Pivot charts
I am using pivot charts to make lots of mini charts from a large set of data. Every time I add to the data and refresh the charts they lose their formatting and I have to go through and reformat everything! I have to change the colours and the font size, it’s driving me crazy. Is there a way to stop it reformatting everything and making it keep my changes? -- Thanks, Rob E. Hi, This is a know problem. Changing a PivotChart removes series formatting in Excel http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q215904 Cheers Andy Rob E wrote: > I am using pivot charts to make ...

Problem With European Formatting of Amounts
I have received a spreadsheet from Europe which has periodS for the 1000's separator and commas for the decimals separator (i.e. $1.234,56 instead of $1,234.56 as commonly used in the USA). To compound the problem, the figures have a single quote in front which I believe makes them text instead of number format... I am unable to perform any calculations with this kind of format! What can I do to remedy the situation? (I am unable to get whoever sent me the file to re-send it in some other format.) Things I have tried: * Used Edit -> Replace -> Replace All It does not work beca...

Formatting Dates
I want to enter a date in text as in: January 25, 2001 And then i want Excel to display it as: 1/25/01. When i tryed to format the cells the date is displayed as I have typed it in. Can anyone help me do this? Select all the cells you want in this format, right click, Format Cells, on the Number tab, select 'Date,' then '3/14/98' as the type. Then click OK. When I do this, and enter 'January 25, 2004, the cell changes it to 1/25/04. "davidian" wrote: > I want to enter a date in text as in: > January 25, 2001 > > And then i want Excel to displ...

conditional format problem
I have two conditions 1. m2>0 2. =M2-P2<3 It only pays attention to the 2nd condition. As if its and "or" rather than an "and". I'm using conditional formating off the toolbar. I want to color the cell red if both conditions are met. It works fine if m2> 0 but it also works if m2=0. Why? John Are you using: "Formula Is" And this formula: =AND(M2>0,M2-P3<3) -- HTH, RD ===================================================== Please keep all correspondence within the Group, so all may benefit! ==============================================...

Get rid of stacking format in window displays.
Can you please display things straight across in a line, not stacked? It makes them hard to read, also make windows open up bigger, save my last open size and re-use when opening a window. Also, when display data is subform, make the window resizable so I can drag open to see more data at once. -- Sheri Salomone Please vote to fix this, thanks! ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, foll...

having excel create a new column in a highest to lowest format
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) sorry it sounds confusing but im not sure if it really is. <br><br><i>have a list of names in one column and then a list of numbers next to it, associated to each name. i would like to create a new column where excel automatically takes the highest 7 numbers and puts the names associated to those numbers in rank from highest to lowest. Is this possible? Is there a formula that can do this? Thanks</i> On 3/5/10 11:35 AM, surfishingfool@officeformac.com wrote: > Version: 2008 Operating System: Mac OS X 10.5...

I want mailmerged dates from access to be in UK format
When I merge data from an access database into publisher the dates come out as US format even though both Access2003 and Publisher 2003 and Windows XP Professional are all set to display UK dates. There doesn't seem to be an option to use text formatting pictures like \@"dd/mm/yyy". Is there a workaround that anyone knows of? Have you tried setting up the field in Access as text? -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Dave Mason" <Dave Mason@discussions.microsoft.com> wrote in message news:...

Formatting from Matrix
Hi I have a Risk Assessment Matrix, which I am using as a Lookup Table (using Vlookup & a Match function) to go and find the consequence and the probability of an identified hazard and then return a assessment number (ie, 1.1, 1.2, 3.1). There are 4 colours on the matrix, depending on whether they are High, Moderate, Low risks, etc. I would like the cell that contains the vlookup, returning the assessment rating, to also pick up the colour from the matrix (ie, Red for High and Green for Low). I know that conditional formatting will only allow 3 colours - I need 4 - and they need to be ...

How do I get keep the format (superscript) from a table?
I have a report that is using a vlookup to come up with a value. The vlookup table has cells with superscripts. How do I keep the superscript format when the lookup returns a value. Not all data in the table has a superscript. Formulas return values--not formats. Maybe a macro that would copy|paste would work??? P3SAB$ wrote: > > I have a report that is using a vlookup to come up with a value. The > vlookup table has cells with superscripts. How do I keep the superscript > format when the lookup returns a value. Not all data in the table has a > superscript. -- D...

Conditional Formatting help
I am using Excel 2002 in the office and have many worksheets in a workbook. My first sheet has cells set up as links to the different worksheets. Is it possible to set up each cell(link) to show when the worksheet it is linked to has been modified? I want to know if I can have something similar to what Sharepoint shows when a file has been updated. I don't think you can do it in the sharepoint way but one possibility (not very elegant). Assuming your hyperlink to a sheet was in A1 right click the sheet tab you are linking to, view code and paste in this Private Sub Worksheet_Cha...

Change form control format in code
I am trying to use this code to change the format of a combobox from Number to Text: Me.cmbProjectNumber.Format="Text" but I am having a proplem doing this. I would like to know if the is a better way to do this. Thank you. Ayo, You do not mention the nature of the problem. But "Text" is not one of the valid options for the Format property of a combobox. I think you probably need to do like this instead: Me.cmbProjectNumber.Format="" -- Steve Schapel, Microsoft Access MVP Ayo wrote: > I am trying to use this code to change the format of a combobox f...

How do I set up a conditional format using the value returned by .
The cell reference returns a phone number from a different sheet. If I use C70>0 in conditional formatting it formats even those that don't return a phone number. I think this is because even if there is no phone number returned, the cell still has a value in it because of the cell reference formula. Test for LEN(c70)>0 or even for a specific length if all your phone #s are the same # of characters "RGDeb" <RGDeb@discussions.microsoft.com> wrote in message news:71172F95-55B4-4BBA-94AD-D6DC99B0B14D@microsoft.com... > The cell reference returns a phone nu...

Page format for Calculation Sheet
I've spent some time trying to optimize a standard page with borders and a title area, to behave like a handwritten calculation sheet for engineering. Problem: If the user changes a column or row width or height the borders move, too. I concluded that all borders, col and row dimensions must be locked and the cells sized for maybe 8 digits. If required the user can join cells for wider input. Hence the following q's: 1. Can the sheet be locked to prevent cell dimension changes but allow for user input? 2. Can a "hollow" image of the border and logo be laid over the pa...

Problem with extending list formats and formulas
Hey all- I'm having a problem with extending list formats and formulas using Excel 2000. I know there are limitations to what that feature can do, but I thought I'd check here, since I have a very simple example that isn't working. I create a sheet with two columns. In the column A, I just enter any arbitrary number in each of the first 10 cells. For column B, I want to calculate the difference between the last two values in column A. In other words, B2's formula is =A2-A1, and B3 = A3-A2, etc.. I copy this formula down the first 10 cells of column B (skipping the first r...

Legend / Axis format copy
Hi I would like to copy the formatting of legend or axis from a chart and paste the format in another chart. I don't want to copy entire chart formatting. Is there any way to do this using vba? Thanks Mohan ...

Copying Conditional Formatting
I am trying to copy conditional formatting using formula instead of cell value. I cannot get it to progress down the column. I attached a file to illustrate. I have oversimplified the illustration but in it I would like to apply conditional formatting to column A to highlight the cell in Red if the number is higher that the cell to it's right in column B. I create a simple conditional format in A1 that says if A1 is greater than B1, highlight the cell in Red. That works. My question is how do I copy that format down the column? I tried copy and past special and every other techni...

I want to format my list boxes so that they are check boxes
hello, I am new to Access (I have 2003 version) and I created my table with list boxes. I was wondering if in my form I could change it to check boxes instead. I need to be able to multiselect. I hope I don't need to program anything because I am new to Access. thanks hi, On 15.03.2010 13:46, pascaleinlove wrote: > I am new to Access (I have 2003 version) and I created my table with list > boxes. I was wondering if in my form I could change it to check boxes > instead. Can you explain it with more details please? What table structure do you have (fields, data...

How do I make a Custom Datre Format ie 01.01.05 WK1 (WK is Week 1) sorry about previous post
...