Serializing Array with array "name" in the XML

I need help serializing an array without including the array "name".  I am
writing in C# and using the XmlSerializer to serial classes.

I am trying to serialize a class with an array in it like the one below.

public class myclass
{
    public imagecontext;
    public myimage[] images;
}

public myimage
{
    public string name;
    public string path;
}

It will serialize something like this...

    <myclass>
        <imagecontext>my context</imagecontext>
        <images>
            <myimage>
                <name>Image1</name>
                <path>somepath</path>
            </myimage>
            <myimage>
                <name>Image2</name>
                <path>otherpath</path>
            </myimage>
        </images>
    </myclass>

What I would really like is to get the XmlSerializer to not serialize the
name of the array (i.e. <images>).  I need for the images to be children of 
the <MyClass>, not children of <Images>. I want it to serialize like 
below...

    <myclass>
           <imagecontext>my context</imagecontext>
           <myimage>
                <name>Image1</name>
                <path>somepath</path>
            </myimage>
            <myimage>
                <name>Image2</name>
                <path>otherpath</path>
            </myimage>
    </myclass>




-1
1/24/2006 7:51:11 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
972 Views

Similar Articles

[PageSpeed] 34

Doing something like

public class myclass
{
   public imagecontext;
    [XmlElement(Type=typeof(myimage),ElementName="myimage")]
   public myimage[] images;
}

may do what you are looking for.

"Rick Francis" <rickfrancis@adelphia.net> wrote in message 
news:s5adncHdObGyGEveRVn-tw@adelphia.com...
>I need help serializing an array without including the array "name".  I am
> writing in C# and using the XmlSerializer to serial classes.
>
> I am trying to serialize a class with an array in it like the one below.
>
> public class myclass
> {
>    public imagecontext;
>    public myimage[] images;
> }
>
> public myimage
> {
>    public string name;
>    public string path;
> }
>
> It will serialize something like this...
>
>    <myclass>
>        <imagecontext>my context</imagecontext>
>        <images>
>            <myimage>
>                <name>Image1</name>
>                <path>somepath</path>
>            </myimage>
>            <myimage>
>                <name>Image2</name>
>                <path>otherpath</path>
>            </myimage>
>        </images>
>    </myclass>
>
> What I would really like is to get the XmlSerializer to not serialize the
> name of the array (i.e. <images>).  I need for the images to be children 
> of the <MyClass>, not children of <Images>. I want it to serialize like 
> below...
>
>    <myclass>
>           <imagecontext>my context</imagecontext>
>           <myimage>
>                <name>Image1</name>
>                <path>somepath</path>
>            </myimage>
>            <myimage>
>                <name>Image2</name>
>                <path>otherpath</path>
>            </myimage>
>    </myclass>
>
>
>
> 


-2
1/25/2006 10:53:44 AM
Clive,
Thanks, it worked great.

Rick Francis

"Clive Dixon" <clived.noluncheonmeat@digita.noluncheonmeat.com> wrote in 
message news:%23RZ1e2ZIGHA.208@tk2msftngp13.phx.gbl...
> Doing something like
>
> public class myclass
> {
>   public imagecontext;
>    [XmlElement(Type=typeof(myimage),ElementName="myimage")]
>   public myimage[] images;
> }
>
> may do what you are looking for.
>
> "Rick Francis" <rickfrancis@adelphia.net> wrote in message 
> news:s5adncHdObGyGEveRVn-tw@adelphia.com...
>>I need help serializing an array without including the array "name".  I am
>> writing in C# and using the XmlSerializer to serial classes.
>>
>> I am trying to serialize a class with an array in it like the one below.
>>
>> public class myclass
>> {
>>    public imagecontext;
>>    public myimage[] images;
>> }
>>
>> public myimage
>> {
>>    public string name;
>>    public string path;
>> }
>>
>> It will serialize something like this...
>>
>>    <myclass>
>>        <imagecontext>my context</imagecontext>
>>        <images>
>>            <myimage>
>>                <name>Image1</name>
>>                <path>somepath</path>
>>            </myimage>
>>            <myimage>
>>                <name>Image2</name>
>>                <path>otherpath</path>
>>            </myimage>
>>        </images>
>>    </myclass>
>>
>> What I would really like is to get the XmlSerializer to not serialize the
>> name of the array (i.e. <images>).  I need for the images to be children 
>> of the <MyClass>, not children of <Images>. I want it to serialize like 
>> below...
>>
>>    <myclass>
>>           <imagecontext>my context</imagecontext>
>>           <myimage>
>>                <name>Image1</name>
>>                <path>somepath</path>
>>            </myimage>
>>            <myimage>
>>                <name>Image2</name>
>>                <path>otherpath</path>
>>            </myimage>
>>    </myclass>
>>
>>
>>
>>
>
> 


2
1/25/2006 4:08:58 PM
Reply:

Similar Artilces:

Two differently named folders for IDE Hard Disk Drives?
Hello, on our CEPC device, two CF cards can be mounted as IDE HDDs. In storage manager registry settings, I can only define one name for the profile "HDProfile". If a 2nd card is detected, it gets a number concatenated (e.g. "Flashdisk:" and "Flashdisk2:") Is it possible to give the second store of the same type a different name (e.g. "Flashdisk" and "Storage card")? Thanks in advance. Then change the profile name the IDE key refers to. You should have something like this in your reginit.ini: [HKEY_LOCAL_MACHINE\Drive...

SMTP Server Name -- DNS
We are about to migrate to Exchange 2003 from Exchange 5.5 (late we know :) We are testing out the SMTP to the internet and things are working well, execpt for those sites that are doing REVERSE lookups on the server names. We have setup reverse lookup for our outbound severs as or normal name space, but it seems when the messages are delivered, they are looking up the active directory domain name (which naturally isnt on the outside of our network), instead of the public name space name for the server. Example: AD Server Name: SERVER1.DS.DOMAIN.COM External Name Space: SERVER1.DOMAIN.CO...

Change Acct Name in Money 2004
I've change the name of an investment account in Money 2004 using change account details, but when I try to transfer funds between accounts, it still shows the old account name, not the new one. Is there a different way to maintain the account name the works? Did you change both the investment account name and its associated cash account name? "Steve" <anonymous@discussions.microsoft.com> wrote in message news:87bf01c3e92e$62890460$a601280a@phx.gbl... > I've change the name of an investment account in Money > 2004 using change account details, but when I tr...

Employee name change
One of the employees at a client of mine just got married and her last name has changed. The site is using SBS 2003 R2. The primary mail system is the POP3/SMTP corporate web hosted by a third party, while the Exchange server deals with in house mail and shared folders; calendars primarily. What is the best, easiest, etc., way to deal with this. Thanks for any help Doug Sanders Fist I'd configure it on the Third party. make sure both OLD and NEW names can receive email. (this way she won't lose email) Then change it on the SBS and Make her primary her ...

outlook webaccess does not show contact names #2
Greetings, I have just installed exchange 2003 and do not see any names in the contact list while using outlook web access. Using regular outlook I have many many names in my contact list but it is not showing when I use OWA. Normally i create new mail, click "To" button and my list of contacts appear. Is there anything on the server end I need to set for thit to work in OWA? ...

SQL Change Column name
I am using VB6 as a front end to an Access97 database. My computer has Access2003 and won't let me edit the columns, tables, etc. I can add/change data, but not the underlying structure of the database. I have found & modified a VB front end that will allow me to add/drop tables, add/drop columns, etc. But it doesn't have an option to change a column name. I've done a bunch of googling on it, and know that using ALTER TABLE and CHANGE is supposed to do it, but it's not, so I'm wondering if CHANGE is not compatible with Access97. The SQL statement I'm usi...

Use of ADMIN as user/account name
We have been using an email address with "admin" as the user/account name for customers to send general documents to. (in other words the full email address looked something lke this "admin@xyz.com") We will be moving to an MS Exchange email system and were told that you cannot use "admin" as a user/account name on an MS Exchange system because it will cause a variety of problems. Is this true? If so, what problems might occur? On 20 Mar 2007 08:09:17 -0700, "Lanranger" <mike.smith@accesseforms.com> wrote: >We have been using an email addr...

Parse out a name
How can I parse out a Name, ex: John J Jones, into First, Middle Initial, Last Name. Thanks in Advance! Brenda Try using Data/Text to Columns. Following the wizard is straightforward. Andy. "Brenda" <Brenda_Hankes@NCCI.com> wrote in message news:060501c37939$614403d0$a001280a@phx.gbl... > How can I parse out a Name, ex: John J Jones, into First, > Middle Initial, Last Name. > > Thanks in Advance! Brenda, If it's spaces between, just go to Data>Text To Columns and use space as the delimiter. It will automatically move to separate columns then. -- ...

What does the #Name? message mean?
I have a report in which I have a text box which reads: ="As part of your GALEX GI Cycle " & [Cycle] & " Program " & [NUM] & ", data was recently delivered to the Multimission Archive at Space Telescope (MAST). GI data is proprietary for 6 months from this notification." I had this exact same construct in a 2003 report, but not I get this error all the time. The query which is the record source looks fine to me and the fields are the ones in the record source. Make sure that your don't have a control on the report named ...

Macro to select all and name range
I have a workbook with some macros that work on another workbook ("Data.xls"). One thing I want the macro to do, is to select everything in a worksheet named Survey and name the range "Database". This would be equivalent to go to the Data workbook and Survey worksheet, hitting Ctrl+Shift+End and enter Database in the name box. I can't record this action because the code specifies the cells included in the current version of Data.xls, and the number of rows will change. What code can I use to accomplish this? Richard Richard, Try this With Workbooks("D...

Named range row/column reference
Hello, I am using named ranges in a VBA macro StudentNbr is A26:A45 TestWeek is E25:X25 TestScores is E26:X45 As you can see this is a grid of data with student numbers down th left side, test week numbers across the top and the grid containin test scores. I would like to update the cells in TestScores based on the positio of the values in the StudentNbr and TestWeek named ranges using: Range("TestScores") (vStudentNbr,vTestWeek).value = vTestScore *Is there a way to get vStudentNbr and vTestWeek as relative reference to the beginning of their respective named ranges? *...

Determining if path name exist
How do I find out if a Path Name exist. I have a CString that contain a Path Name (no file name associated with this path name). All I want to do is determine if this path name exist and if it doesn't, prompt the user that the path name does not exist and if the path name should be created. Thanks John On Wed, 28 Jan 2004 09:17:10 -0800, John <jvasquez@spam.getntds.com> wrote: >How do I find out if a Path Name exist. > >I have a CString that contain a Path Name (no file name associated >with this path name). All I want to do is determine if this path name >exist...

Display names puzzle, can you help?
Here's my situation: We've acuquired a company, and now we're adding those users onto our mail system. I can deal with all the issues related to DNS, etc, but one real thorn in our side is the display names. This company used only "firstname@companyname.com" for an e-mail address, AND the real clincher is that they only use "firstname" as a display name. Our corporate standard as the aquiring company is to use firstname.lastname@company2name.com. However, this little company we bought has gone ahead and put employee pictures on the web (with only fi...

Easy way to create a bunch of worksheets and name them
Let's say I have a workbook and want to create 60 or so worksheets. But I don't want to go in a name them after I create them. What if I had a list of names...like in a column. Then I wanted to run a macro that would create a worksheet for each name in the list and name it. What would the code look like? Frank it might look something like this: Sub InsertSheets() Dim Cell As Range Dim NewSheet As Worksheet For Each Cell In Range("A1:A" & Range("A65536").End(xlUp).Row) Set NewSheet = _ Sheets.Add(After:=Sheets(Worksheets.Count)) NewSheet.Name =...

Alternate server name
IS there a way to establish an anternate server name...my servername is olng and cumbersome to type in.. is there a way to establish like an "alias" and why are so many of the other discussion groups here empty ..I just posted this quetion in the DNS group....and at least for me that group has no post's at all in the folder ?? Create a CNAME in DNS that point to the existing "A" Record. -- Phillip Windell The views expressed, are my own and not those of my employer, or Microsoft, or anyone else associated with me, including my cats. --...

Changing the account name part of the From address in outbound ema
When emails are sent from one of our pcs, the name of the pc (APC017) is being displayed to the email's recipient as part of the 'From:' field (ie. the From field shows APC017<mail@mycompany.com>). How do we change the APC017 part? We have changed the Display Name and other properties but it has not made any difference. We don't want to change all of our email addresses - just customise this specific one. We are using Small Business Server 2003 with Exchange 2003 SP2 and Outlook 2003. Many thanks Graham The answer was to rename the mailbox in Exchange System M...

Procedure to remove all named ranges #2
Don, Thanks for the tips great stuff!!! One question why is it that when w email this sheet that now has no code named ranges or objects that it i prompting the user to enable/disable macros when opening it? There i nothing but text and a couple of our embedded pictures in it. Funny thing is that if you open the attachment and save it to a folde then reopen it later it does not prompt you to enable/disable macros -- Doctor ----------------------------------------------------------------------- DoctorV's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=514 View t...

names ans addresses
hi to everyone, have only just joined, so please treat me as an idiot in terms of your writings to me my first question is i want to make a name and address list in excel 2007 and for each column i want name first name introd by like dislike address now what i want to do is to be able to interlink all the columns so that by the typing of word like theatre or gardens i can isolate the others and only to bring up those that like that subject please remember IDIOT language for me please :laugh:laugh:laugh:laugh -- bobbydog --------------------------...

Can I use a named range in SUMPRODUCT?
I am trying to use a named range in SUMPRODUCT to shorten my formula. My named range is called Data_Sel_WA. My formula is: =SUMPRODUCT(--(Data_Selection!$D$7:$D$25=$A10),Data_Sel_WA) My named range is defined as: =Data_Selection!$F$7:$F$25,Data_Selection!$J$7:$J$25,Data_Selection!$N$7:$N$25,Data_Selection!$R$7:$R$25,Data_Selection!$V$7:$V$25,Data_Selection!$Z$7:$Z$25,Data_Selection!$AD$7:$AD$25 The formula is returning a #VALUE error. When the formula had the actual cell ranges instead of the named range it worked. What's wrong? Thanks, Joe M. Don't think discont...

Set rules as per the display name
Outlook 2002 Is there any way to setup a rule that applies to the display name only. Thanks. "falcios" <falcios@discussions.microsoft.com> wrote in message news:D75BB8E7-401D-4BAA-954C-47A6EE4C4C6E@microsoft.com... > Outlook 2002 > Is there any way to setup a rule that applies to the display name only. What do you want the rule to do? -- Brian Tillman [MVP-Outlook] I want the rule to delete the email with that display name? I tried using message header and it didn't work. "Brian Tillman [MVP-Outlook]" wrote: > "falci...

Named Range in ANOTHER workbook #2
hi I have defined many NamedRanges in 2 workbooks. and copying between NamedRange(s) between the 2 workbooks is desired. I have a need to access THOSE NamedRanges from the 3rd book, thus I need some reference method like: wb_s.range("ThisRange") wb_t.range("ThatRange") <do not prefer BOOK.SHEET.RANGE way> so that I can do dim A as Variant A = wb_s.range("From") wb_t.range("To")=A if refencing like BOOK.Range(Name) is not feasible, then dim A as Variant wb_s.activate A = range("From") wb_t.activate range("To")=A but this is n...

Dynamic Named ranges in formulae
I have a named range 'CountRecords' created by the following :- =OFFSET(RecordOfRounds!$A$1,52,0,COUNT(RecordOfRounds!$A:$A)-5,1) which in the current sheet is the range A53:A80 - this is displayed surrounded by a blue line when I type 'CountRecords' into the 'Name Box' I then insert the following in cell A2 :- =COUNT(CountRecords) and the display is '0' If I enter COUNT(A53:A80) I get (correctly!) '28'. What am I doing wrong? Sandy somewhere type =count(a:a) to see what you get. -- Don Guillett Microsoft MVP Excel SalesAid Software dg...

auto locate "send To" name....
Here at work, when you type in a "To" name, if there are multiples contacts for the same name, a pop-up box will appear containing the various user anmes and you can select the one you want. I have a user who mentioned to me tha his Outllok client at home does not do this. Since I don;t want to spend the time to research this non-work related issue, can some quickly tell me how you turn this functionality on? Thanks, Brad He probably uses the cache feature then (stored in the nk2-file). When he types a name of someone he has mailed before Outlook will suggest that name. When ...

3 cells are named
Hi, I have three cells named and want to use that name in a vba chart procedure for a xl3DColumnStacked chart ActiveChart.SeriesCollection(1).Values = sheet1.Range(scol1v) I used in the procedure: Dim scol1v As String Let scol1v = "ThreeValues" Meaningless note: I used sheet1 as Name and CodeName In the excel GUI you find the name "ThreeValues" is defined as this reference: 'sheet1'!$A$1;'sheet1'!$A$4;'sheet1'!$A$6 I thougt it just was to specify the sheet + name, but the debbugger doesn't like that. what am i doing wrong? Shall I use ar...

SOP Invoice Customer Name
Is there anyway to have the Bill to Name, different than the Ship to Name? We have instances where we ship to one company and bill a different one. Like a Drop Ship Purchase Order. I have tried the bill to and ship to addresses but it still uses the customer name from the Invoice header. thanks! -- Doug Doug, If all you need is to ship the merchandise to one place and have somebody else pick up the tab, you could perhaps use National Accounts if registered. If not, then you could perhaps use the contact name on the shipto address to capture the company name and expose that to Rep...