473,383 Members | 1,953 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,383 software developers and data experts.

Force XmlSerializer.Deserilize to ignore empty XML tags

I'm having trouble deserilizing an xml node that has empty tags. See
XML:

<ContentCampaigns>
<ContentCampaign>
<ad_id_source type="integer"></ad_id_source>
<billing_code type="integer"></billing_code>
<birth type="datetime">2007-08-24T16:15:16-07:00</birth>
<body>this campaign has alerady been sent</body>
<category_id type="integer">1</category_id>
<created_at type="datetime"></created_at>
<id type="integer">4</id>
<name>complete_campaign</name>
<notes></notes>
<subject>this campaign is read to send</subject>
<thumbnail></thumbnail>
<updated_at type="datetime"></updated_at>
<valid_after type="datetime"></valid_after>
</ContentCampaign>

This XML is generated from a rails web service and respresents a table
in the database.

When I try to deserilize this the deserlizer fails on the empty tags.
How can I make the deserializer simply ignore these tags as they have
no value anyways...?

Oct 2 '07 #1
5 9890
P.S. Ignore that first <ContentCampaignstag..

Oct 2 '07 #2
"eggie5" <eg****@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
P.S. Ignore that first <ContentCampaignstag..
Take a look at the DefaultValueAttribute, example here
http://msdn2.microsoft.com/en-us/lib...er(VS.80).aspx
and
http://msdn2.microsoft.com/en-us/lib...te(VS.80).aspx.
Alternatively alter the serialisation using the XmlElement(IsNullable =
true) to get this sort of output:
<notes xsi:nil="true"/>
when notes is null.
--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
Oct 2 '07 #3
On Oct 2, 3:45 pm, "Joe Fawcett" <joefawc...@newsgroup.nospamwrote:
"eggie5" <egg...@gmail.comwrote in message

news:11**********************@k79g2000hse.googlegr oups.com...P.S. Ignore that first <ContentCampaignstag..

Take a look at the DefaultValueAttribute, example herehttp://msdn2.microsoft.com/en-us/library/system.xml.serialization.xml...
andhttp://msdn2.microsoft.com/en-us/library/system.componentmodel.defaul....
Alternatively alter the serialisation using the XmlElement(IsNullable =
true) to get this sort of output:
<notes xsi:nil="true"/>
when notes is null.
--

Joe Fawcett (MVP - XML)http://joe.fawcett.name
I tried giving a node the nil attribute but it still errors out as:
"{"Input string was not in a correct format."}"

<?xml version="1.0" encoding="utf-8"?>
<ContentCampaign xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<id>0</id>
<name>serilizatoin test</name>
<category_id>4</category_id>
<subject>i am subject</subject>
<body>i am body</body>
<birth>0001-01-01T00:00:00</birth>
<ad_id_source xsi:nil="true"/>
<valid_after>0001-01-01</valid_after>
<billing_code>0</billing_code>
<created_at>0001-01-01T00:00:00</created_at>
<updated_at>0001-01-01T00:00:00</updated_at>
<notes></notes>
</ContentCampaign>

Oct 2 '07 #4
On Oct 2, 3:45 pm, "Joe Fawcett" <joefawc...@newsgroup.nospamwrote:
"eggie5" <egg...@gmail.comwrote in message

news:11**********************@k79g2000hse.googlegr oups.com...P.S. Ignore that first <ContentCampaignstag..

Take a look at the DefaultValueAttribute, example herehttp://msdn2.microsoft.com/en-us/library/system.xml.serialization.xml...
andhttp://msdn2.microsoft.com/en-us/library/system.componentmodel.defaul....
Alternatively alter the serialisation using the XmlElement(IsNullable =
true) to get this sort of output:
<notes xsi:nil="true"/>
when notes is null.
--

Joe Fawcett (MVP - XML)http://joe.fawcett.name
Hi, the [System.Xml.Serialization.XmlIgnoreAttribute] attribute
completly ignores the attribute, even when it's set to a value. This
won't work. Sometime the nodes have values and sometimes they can be
null.

Oct 2 '07 #5
I didn't write XmlIgnore I wrote DefaultValueAttribute.
Show the code where the notes property is declared where you tried to use
IsNullable.

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
"eggie5" <eg****@gmail.comwrote in message
news:11********************@y42g2000hsy.googlegrou ps.com...
On Oct 2, 3:45 pm, "Joe Fawcett" <joefawc...@newsgroup.nospamwrote:
>"eggie5" <egg...@gmail.comwrote in message

news:11**********************@k79g2000hse.googleg roups.com...P.S.
Ignore that first <ContentCampaignstag..

Take a look at the DefaultValueAttribute, example
herehttp://msdn2.microsoft.com/en-us/library/system.xml.serialization.xml...
andhttp://msdn2.microsoft.com/en-us/library/system.componentmodel.defaul....
Alternatively alter the serialisation using the XmlElement(IsNullable =
true) to get this sort of output:
<notes xsi:nil="true"/>
when notes is null.
--

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

Hi, the [System.Xml.Serialization.XmlIgnoreAttribute] attribute
completly ignores the attribute, even when it's set to a value. This
won't work. Sometime the nodes have values and sometimes they can be
null.

Oct 3 '07 #6

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

Similar topics

3
by: Bob Rundle | last post by:
I'm trying to serialize a class with XmlSerializer. This class implements the IEnumerable interface. I implemented the IEnumerable interface for reasons other than Xml serialization. However I...
3
by: Clark Spencer | last post by:
I have built a small integration app using VS .NET 2003 that extracts orderinformation from a 'webshop'. Extracting the orderinformation works fine. Appending the order elements in the...
1
by: Reader | last post by:
Hello, I would like to know if there is a way to cache the xmlserializer-generated temp files and have the program reuse these cached files upon new application instances. For example,...
4
by: Alexis | last post by:
Hello, Is there a way of telling the XmlSerializer to ignore all namespaces when deserializing. I'm using XmlAttributeOverrides, but I have to do it for every class the OutputObject usses. Is...
3
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as...
1
by: Jamus Sprinson | last post by:
Before I continue, I'm going to begin by saying I'm not by any means an expert- I've been using .NET with C# for about 4 months now, and basically just learning by example and docs. A game...
1
by: scott.ballard | last post by:
Greetings, I am using the .Net Framework XmlSerializer to serialize a class that contains some string properties. The problem is that when a string contains a zero-length string ("") it is...
2
by: Jinsong Liu | last post by:
I have following 3 classes public class MyMainClass { MyCollection<MyObject> m_oMyObjectCollection = null; private string m_sID = string.Empty; public MyCollection<MyObject> Collection {
7
by: kumar.senthil | last post by:
Hi, I'm using XmlSerializer to create an object from the XML string. I would like to know whether I can get a null value for an empty XML element. Actually the XmlSerializer assigns "" (empty...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.