473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Serialisation > ignore element when an attritube is null

Hi everybody

here is a question

I have this class that a want to serialize :

Public Class BOO
<XmlAttributeAttribute()> Public THING As String
<XmlElementAttribute("param")> Public p() As param
End Class

it is (of course) working with this class :

Public Class PARAM
'I have not put the constructors...
<XmlAttributeAttribute()> Public name As String
<XmlAttributeAttribute()> Public X As String
End Class

You understand that I have a array of Param....
sometimes, in this array, some object PARAM does not have a value for the
attribute X

the serialisation looks like

<BOO THING ="hello girls" >
<param name="john" X="booboo" />
<param name="franck" />
<param name="bob" X="boo" />
</BOO>

here, Franck doesn't have a X value....
I simply want to do not have this line, and obtain :

<BOO THING ="hello girls" >
<param name="john" X="booboo" />
<param name="bob" X="boo" />
</BOO>

someone told me to use custom XmlAttributes ....(If X='' then dont write me)

I dont know how to do...
Is there another ways to do that?

Thanks for your help!

lobrys



Nov 11 '05 #1
1 1829
Lobrys,

Attributes will not work here because are trying to exclude individual array
elements based on their content. You cannot attach serialization attributes
to individual array elements.

Your best bet is a wrapper class with a property that exposes the array,
something like (sorry for the C# -- i hope you get the idea):

Warning: Tested in Outlook ;)

public class BooWrapper
{
private BOO b;
public class BooWrapper( BOO otherBoo )
{
b = otherBoo;
}
public Param[] p
{
get
{
ArrayList list = new ArrayList();
for( int i = 0; i < b.p.Length; i++ )
{
if (null != b.p[i].X)
list.Add( b.p[i] );
}

return (Param[]) list.ToArray( typeof( Param ) );
}
set
{
/// TODO
}
}

// TODO: more ...
}
HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET

"lobrys" <lo**********@free.fr> wrote in message
news:#$**************@TK2MSFTNGP12.phx.gbl...
Hi everybody

here is a question

I have this class that a want to serialize :

Public Class BOO
<XmlAttributeAttribute()> Public THING As String
<XmlElementAttribute("param")> Public p() As param
End Class

it is (of course) working with this class :

Public Class PARAM
'I have not put the constructors...
<XmlAttributeAttribute()> Public name As String
<XmlAttributeAttribute()> Public X As String
End Class

You understand that I have a array of Param....
sometimes, in this array, some object PARAM does not have a value for the
attribute X

the serialisation looks like

<BOO THING ="hello girls" >
<param name="john" X="booboo" />
<param name="franck" />
<param name="bob" X="boo" />
</BOO>

here, Franck doesn't have a X value....
I simply want to do not have this line, and obtain :

<BOO THING ="hello girls" >
<param name="john" X="booboo" />
<param name="bob" X="boo" />
</BOO>

someone told me to use custom XmlAttributes ....(If X='' then dont write me)
I dont know how to do...
Is there another ways to do that?

Thanks for your help!

lobrys



Nov 11 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
129
by: Torbjørn Pettersen | last post by:
I've started cleaning up my HTML and implementing CSS. So far I've used FrontPage, but am switching over to DreamWeaver. Reading a bit on W3Schools.com and W3.org I see there are a lot of HTML...
44
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
23
by: Andrew Thompson | last post by:
This is intended to fix a long standing (cough)Java(cough) problem with which I'm sure some of you will be familiar. Sun recommends using the <OBJECT>/<EMBED> elements to cater for Java...
4
by: Shailendra Batham | last post by:
Hi guys,Does any1 know what this error is all about, what I am trying to do is deserialize a XML, below is my code, let me know what I am doing wrongpublic class test{xin = "<?xml version='1.0'...
7
by: Danny Tuppeny | last post by:
Hi All, I've been going through Google Groups, but nothing seems to quite match my problem. It's hard to post a WSDL or anything at the moment (it's not my service, I'm just using it), but maybe...
28
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
2
by: ashwinij | last post by:
Hello The steps which i am doing in my program 1) I am having an xml file. 2) I am performing some updations in the file using XQueryUtil class from nux package. 3)After that i am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.