Conditional XML serialization???

Hi,

I've got two classes - Entity which will have an array of Child objects
in it and Child class.

class Entity
{

public Child[] Children;

}

class Child
{

public string Name;
public string Description;

}

I want to be able to serialize this class into two different XMLs.

1) looks like,
<Entity>
          <Child Name="" Description=""/>
          <Child Name="" Description=""/>
          <Child Name="" Description=""/>
</Entity>

2) looks like,
<Entity>
          <Child Name=""/>
          <Child Name=""/>
          <Child Name=""/>
</Entity>

How to do this? Coz If I use [XmlIgnore] attribute on class Child's
description attribute, then it won't allow me to produce Xml (1).
So its basically to control serialization during runtime.

My serialization code currently looks like,

// Serialize the Entity object in to an XML document, and we are done.
                TextWriter objTextWriter = null;
                XmlSerializer objXmlSerializer = new
XmlSerializer(typeof(Entity));
                objTextWriter = new StreamWriter(@"C:\Entity.xml");
                objXmlSerializer.Serialize(objTextWriter, objEntity);

Any help in this regard would be of great help. MS experts help me out
here... please..

Cheers,
Vin

0
kgvinayak (4)
1/16/2006 9:55:18 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
552 Views

Similar Articles

[PageSpeed] 22

How about modifying your code to:

class Child
{
public string Name;
public string Description;
[XmlIgnore]
public bool DescriptionSpecified;
}

The framework serialization process checks for a Boolean field with the same 
name as each field but suffixed with "Specified". If such a Boolean field 
exists, it will only serialize the original field if the Boolean field's 
value is 'true'.


"Vinayak Kamat" <kgvinayak@gmail.com> wrote in message 
news:1137448518.394742.90880@z14g2000cwz.googlegroups.com...
> Hi,
>
> I've got two classes - Entity which will have an array of Child objects
> in it and Child class.
>
> class Entity
> {
>
> public Child[] Children;
>
> }
>
> class Child
> {
>
> public string Name;
> public string Description;
>
> }
>
> I want to be able to serialize this class into two different XMLs.
>
> 1) looks like,
> <Entity>
>          <Child Name="" Description=""/>
>          <Child Name="" Description=""/>
>          <Child Name="" Description=""/>
> </Entity>
>
> 2) looks like,
> <Entity>
>          <Child Name=""/>
>          <Child Name=""/>
>          <Child Name=""/>
> </Entity>
>
> How to do this? Coz If I use [XmlIgnore] attribute on class Child's
> description attribute, then it won't allow me to produce Xml (1).
> So its basically to control serialization during runtime.
>
> My serialization code currently looks like,
>
> // Serialize the Entity object in to an XML document, and we are done.
>                TextWriter objTextWriter = null;
>                XmlSerializer objXmlSerializer = new
> XmlSerializer(typeof(Entity));
>                objTextWriter = new StreamWriter(@"C:\Entity.xml");
>                objXmlSerializer.Serialize(objTextWriter, objEntity);
>
> Any help in this regard would be of great help. MS experts help me out
> here... please..
>
> Cheers,
> Vin
> 


0
1/17/2006 11:25:04 AM
It works !!!!

Thank you very much Clive.
That's what I was looking for.

Cheers,
Vin

0
kgvinayak (4)
1/17/2006 9:39:32 PM
Reply:

Similar Artilces:

Question about signing XML and RSA
Hello. I am trying to sign my XML files with private/public keys but I have noticed that initiating the RSA key with either RSA.Create() or FromXMLString() takes a lot of time. I wonder why? On my machine (which is pretty fast) it takes seconds to call RSA.Create() Is it possible to skip this part and read in the keys directly? What is the fastest way to get a RSA key to pass SignedXML.SigningKey ? I have generated keys already. Thank you. /David. "David Lindgren" <david.lindgren@hogia.se.REMOVE!> wrote > I am trying to sign my XML files with private/public keys but I ...

Today Conditional Format
I have a column which calculated a date based on 3 working days from a date input into a diff column. What I want to do I have the calculated date appear bold if that date has passed based on the current date. For example if I input 01/08/11 the next column calculates 04/08/11 (3 working days). I want the caluclated date to appear bold when I open the spreadsheet on the 05/08/11 ro show the calculated date has passed. I can use conditional formatting but can't get the syntax right Regards Andy Win XP Pro Office 2010 Andy Roberts presented the following explanation : > I ha...

Two Condition Vlookup?
I am currently trying to create a function that searches through an array for two exact column values which allows me to retrieve a third column value. For example: Type of Fruit Date Packaged Amount of Fruit Apples June 100 Oranges June 50 Apples July 75 Grapes July 50 In this example, I would be looking to retrieve the Amount of Fruit (Apples) that was packaged in July. I would be putt...

Sending XML data to asp server... Is there any problem?
Hi, I transform client XML data to IIS server by WinInet API. In IIS server, asp parse request XML data and result save in MS-SQL. I can read XML data by this function, but I can send XML data... The function that I use is that... BOOL CXMLUtil::RequestHttpServer(LPCTSTR lpszMethod, LPCTSTR lpszURL, LPCTSTR lpszRequest, LPCTSTR lpszHeader, CString &strResponse, CString &strStatus) { BOOL fResult = TRUE; CInternetSession iSession; CHttpConnection *pHttpConnection = NULL; CHttpFile *pHttpFile = NULL; CString str_ErrorText; DWORD dwErrorCode = 0; CString strUrl = lpszURL; ...

Query condition by date range
I'm trying to create a query to base a report from. I need it to return records within a date range that needs to be specified, as in specifying the beginning date and having the current date as the end date. A field is included in the query that has listed dates in the format mm/dd/yyyy. How would I write the criteria? I have part of it ready - [Please enter starting date:] . I know that's how you get the little question window. On Tue, 4 Dec 2007 14:51:00 -0800, silva wrote: > I'm trying to create a query to base a report from. I need it to return > records within a...

Need help with conditional formula (Excel 97)
Can anyone give me the correct syntax for the following formula: if A1 is blank, and B1 is more than zero, then display B1, otherwise display nothing (blank cell) Thank you JD =IF(AND(A1="",B1>0),B1,"") Success! -- met vriendelijke groetjes "Jake D" <JakeD@djhtend.com> schreef in bericht news:crkto4lv30u7uujv27ek8okr0us5t9oj10@4ax.com... > Can anyone give me the correct syntax for the following formula: > > if A1 is blank, and B1 is more than zero, then display B1, otherwise > display nothing (blank cell) > > Thank you > > ...

Conditional formatting if condition of an if statement is true and a string value is displayed
Dear Experts: I got a nested 'IF'-Formula in an excel cell that returns nothing if the condition is false. I would like to conditionally format this cell with grey shading if the condition is true and a string value is displayed. How can this be achieved using excel conditional formating functionality ? Help is much appreciated. Thank you very much in advance. Regards, Andreas Let's say your doing this conditional formatting in cell K17. In conditional formatting (xl2003) choose the FormulaIs: option and enter: =$K$17<>"" choose your formatt...

Schemas referred in XML
I have an xml. It was generated from different schemas. I want to know the namespaces and the schemas that are reffered in that XML. So that i can add the Namespaces and Schemas to the Namespace Manager and Validate them. How do i dothat. One more time in simple words. I had an xml. i want to know how do i know what namespaces and xsds are refered? please help, thank you ...

Conditional Field in Queries
Is there a way to make a field in a query conditional so that it only displays the value if the value is equal to something specifically set? Thanks. Nick Nick.Korynski@gmail.com wrote: > Is there a way to make a field in a query conditional so that it only > displays the value if the value is equal to something specifically > set? Thanks. > > Nick Explain "the value is equal to something specifically set". -- Rick Brandt, Microsoft Access MVP Email (as appropriate) to... RBrandt at Hunter dot com ...

XML validation error. Help required
XML validation error. Help required If anyone can help me, thankyou, thankyou... When I run this code code I get this error: The data at the root level is invalid. Line 1, position 39. I can't work out what the error is. Can you??? original code: Dim oRead As XmlTextReader Dim oValid As XmlValidatingReader Try oRead = New XmlTextReader("C:\custdoc.xml") oValid = New XmlValidatingReader(oRead) AddHandler oValid.ValidationEventHandler, New Schema.ValidationEventHandler(AddressOf ValidationError) oValid.Schemas.Add("newschema", "C:\custschema.xsd") oValid....

How do i use Conditional formatting for 3+ conditions ?
I have a text box in a report which highlights in colour current members in a list of past and present member names. I have six types of current members that I want to highlight, but with conditional formatting I can only use 3 conditions in the members [Type] field. I have tried [Type]="Full member" Or "Life member" but the "Or" doesn't work ! Is there a way to do this ? thanks .. Roger CF is limited to 3 contitions, but you can use OR in those expressions. If you set Condition1 to Expression, you can use: ([Type] = "Full member") Or (...

How do I write a response to a request from an xml data island?
I need to know the code I must write to respond xml to a data island as a result from a src request from the data island. Thanks so much Assuming the data island has a src attribute like: "getXML.asp", this ASP page would do it: <%@ language="JScript"%> <% var xmlDoc = new ActiveXObject("MSXML2.DomDocument"); xmlDoc.loadXML("<root>Some XML</root>"); Response.ContentType="text/xml"; xmlDoc.save(Response); %> Regards, Mike Sharp "Nicole Schenk" wrote: > I need to know the code I must write to respond x...

Help with Conditional formatting with Dates
Hi there, I have a spreadsheet in which I have to monitor various dates which are in different columns (i.e. (1) Date Tender Released, (2) Date Company Selected, (3) Date Draft Contract Forwarded, (4) Date Contract Signed etc...). Would if be possible to Conditional Format and have diffirent ROWs highlighted for each individual Contracts (I have 300 running contracts running) every time a date is filled in these different columns: Initial Step (1) = Yellow (Call for Tender released) Step (2) = Blue (Company Selected) Step (3) = Brown (Contract under Process) Step (4) = Green (Contract Si...

Conditional null value
Wondering if anyone can suggest a way to simplify the following code, which I’m using in the OnFormat event of a report. If Not IsNull(DLookup("[ICD2]", "EntryICDs", "[EntryNum] = " & Me! [PtAcct#])) Then Me![Field192] = Replace(DLookup("[ICD2]", "EntryICDs", "[EntryNum] = " & Me![PtAcct#]), ".", " ") End If If Not IsNull(DLookup("[ICD3]", "EntryICDs", "[EntryNum] = " & Me! [PtAcct#])) Then Me![Field194] = Replace(DLookup("[ICD...

Save and load crypted XML
Hi I need to save / load XML data in crypted format. I'm using .net 1.1. Thanks. "nano2k" <adrian.rotaru@ikonsoft.ro> wrote in message news:1189768942.560777.294920@d55g2000hsg.googlegroups.com... > Hi > > I need to save / load XML data in crypted format. > I'm using .net 1.1. > > Thanks. What you really need is a specification. Decide how you are going to encrypt, and equalising both sides of the equation on transposition; how you are going to decrypt. These steps pre-empt input and output, and no, generic methods are not secure because they are...

Help
Forgive me if "Conditional Sums" is not the accurate word for what I am trying to accomplish... I'm at a loss for what to call this situation. What I have is a spreadsheet totaling attendance figures for classes taught by two people (Dave and Cary). Column A lists their name, and next to it in Column B is the number of people who attended that class. What I need is a formula that will look at the sheet and report in a given cell the total for attendance for each person. I can work basic formulas like SUM, but that will give the total for the entire column, when what I n...

XML Receipt and Conditions
I wanted to make a small adjustment to the receipt when a certain condition is met. If a particular word (eg. family) is typed into the comment on an item I wanted something slightly different to happen to the receipt I've just about got it, just stuck on the condition tag <IF> <CONDITION>len(Entry.Comment)</CONDITION> <THEN> I can get it using len but this makes it happen for any word, is there anyway I can make it so that it is more specific ie Entry.Comment contains '%family%' try <IF> <CONDITION>Entry.Comment like '%family%'&...

conditionally restricting values in excel
Hello, I want to restrict values in a particular column based on the value in other column. For eg. if column A has value int then column B should be restricted to values 1,2,3,4,5 if column A has value bool then column B should be restricted to values true and false. if column A has value string I dont want any validation to be done and the list box should not appear. Is this possible..... How do I achieve this ? Can I use macros to do this? How? Thanks Hi as a starting point: http://www.contextures.com/xlDataVal02.html >-----Original Message----- >Hello, >I want to restrict ...

Conditional formating condition..?
Hi All I have 2 CF conditions associated with a cell (C14), one of which is: Formula is =OR($C$4="Fred SOMEBODY",C14<>"10:30:00") What happens when this is true isn't important/relevant. The value in the cell appears as 10:30 (formatted as custom/hh:mm) but the value in the 'formula window' is actually 10:30:00. This type of condition works fine when the cell contains a simple number (or text) but I can't get it to work for either times or dates. I have tried it with and without the inverted commas (around the time value) and have tried using 10:30 ...

Condition Formatting!
How do I make a row of cell (shading) that change to red color when the word "trial" or "limit" is entered? i.e cell 3f contain the word "trial". From the column of trial to the 1st column, the entire row 3a to 3f will be red? a b c d e f 1 2 3 Trial 4 5 6 Here's some VBA you could paste into the codebehind page for that sheet: Private Sub Worksheet_Change(ByVal Target As Range) If UCase(Target.Value) = "TRIAL" Or UCase(Target.Value) = "LIMIT" T...

chart conditional formatting
I have a line chart with 3 lines, red, blue and green. Is there any way I can conditionally format some, but not all, points on the red line to colour white - ie make them invisible. I have looked at Jon Peltier's site - he addresses conditional formatting - but cannot see a solution there. Thanks in advance to all who try to help. -- bob777 ------------------------------------------------------------------------ bob777's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=28504 View this thread: http://www.excelforum.com/showthread.php?threadid=488635 Hi, Ha...

Conditional Picture?
Does anybody knows how to insert one picture that changes without use intervention everytime the result of another cell changes? eg.: If the cell A1="Alex" the cell A2=Picture of Alex. Then if change the cell A1 to "Mike" the cell A2 displays the picture of Mike -- Message posted from http://www.ExcelForum.com Hi Alex This macro example from this group a long time ago you can use. The jpg files must have the same names as the number you type in cell "a1" Change the path to the files in the code. Place the code in the Sheet module Right click on a sheet tab ...

Xml and Serialization.
Hi, I would like to display some properties of an object of mine as XmlElement "Content", not as an nested Element That is : <.MyObject> TheValueGoesHere <./MyObject> currently it display as : <.MyObject> <.The_Value>TheValueGoesHere<./The_Value> <./MyObject> How do I do ? I fumbled with [XmlAttribute], [XmlElement] declarations ... to no avail. Any idea, anyone ? Regards. [XmlText] example: http://www.winisp.net/cheeso/srcview.aspx?dir=xml-serialization&file=XmlText.cs -D -- Dino Chiesa Microsoft Developer Division d i n o...

Serialization of ArrayList as root element
Can anyone tell me how to setup serialization attributes for an ArrayList as a root element ? ...

Conditional Formatting for 4 conditions
How can I set up conditional formatting for the following: >3.5 = red 2.5 - 3.49 = yellow 2 - 2.49 = green <2 = blue Thanks, Steve Set all the cells to one of the colours that apply the 3 conditions to them via CF, effectively 4 colours. -- HTH Bob "Steve" <Steve@discussions.microsoft.com> wrote in message news:3E34D7F5-545C-4177-83C7-93A735398F42@microsoft.com... > How can I set up conditional formatting for the following: > >>3.5 = red > 2.5 - 3.49 = yellow > 2 - 2.49 = green > <2 = blue > > Thanks, &...