473,503 Members | 13,285 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlIgnoreAttribute() ignoring other attributes then intended

Perhaps I'm using this wrong. When I use
[System.Xml.Serialization.XmlIgnoreAttribute()] above an attribute I don't
want serialized it ignores the attribute. It also ignores some other
attributes. Have I done something wrong?

Here's the serialization code

public Form1()

{

testClass test = new testClass();

InitializeComponent();

try

{

XmlSerializer x = new XmlSerializer(typeof(testClass));

TextWriter writer = new StreamWriter("\\" + "test.xml");

x.Serialize(writer, test);

}

catch (Exception e)

{

MessageBox.Show(e.ToString());

}

}

Here's the class being serialized. Sorry that it's so long but I couldn't
reproduce this with a shorter class I made

namespace XML_test1{

using System.Xml.Serialization;

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Xml;

using System.Xml.Schema;

using System.IO;
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]

// [System.SerializableAttribute()]

[System.Diagnostics.DebuggerStepThroughAttribute()]

[System.ComponentModel.DesignerCategoryAttribute("c ode")]

[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]

public partial class testClass {

private string eventTypeField;

private string pSCommonField;

private string loadArrivalNumberField;

private string incomingLDSNumberField;

private string transportIdentifierField;

private string sourceField;

private string cutblockIDField;

private string fieldScaleFlagField;

private string fieldScaleDeckIDField;

private string weighSlipNumberField;

private string originatingScaleSiteNumberField;

private string splitLoadField;

private string beachcombField;
private string checkScaleField;

private string pSMeasureField;

private string dDNField;

private string dvField;

private bool beachcombFieldSpecified;
[System.Xml.Serialization.XmlElementAttribute(Order = 0)]

public string EventType

{

get

{ return this.eventTypeField;}

set

{this.eventTypeField = value;}

}
[System.Xml.Serialization.XmlElementAttribute(Order = 1)]

public string PSCommon

{

get

{ return this.pSCommonField;}

set

{ this.pSCommonField = value;}

}
[System.Xml.Serialization.XmlElementAttribute(Order = 2)]

public string LoadArrivalNumber

{

get

{return this.loadArrivalNumberField; }

set

{this.loadArrivalNumberField = value; }

}
[System.Xml.Serialization.XmlElementAttribute(Order = 3)]

public string IncomingLDSNumber

{

get

{ return this.incomingLDSNumberField;}

set

{this.incomingLDSNumberField = value;}

}
[System.Xml.Serialization.XmlElementAttribute(Order = 4)]

public string TransportIdentifier

{

get

{ return this.transportIdentifierField; }

set

{ this.transportIdentifierField = value;}

}
[System.Xml.Serialization.XmlElementAttribute(Order = 5)]

public string Source

{

get

{ return this.sourceField; }

set

{ this.sourceField = value;}

}
[System.Xml.Serialization.XmlElementAttribute(Order = 6)]

public string CutblockID

{

get

{return this.cutblockIDField;}

set

{this.cutblockIDField = value; }

}
[System.Xml.Serialization.XmlElementAttribute(Order = 7)]

public string FieldScaleFlag

{

get

{ return this.fieldScaleFlagField; }

set

{ this.fieldScaleFlagField = value; }

}
[System.Xml.Serialization.XmlElementAttribute(Order = 8)]

public string FieldScaleDeckID

{

get

{ return this.fieldScaleDeckIDField; }

set

{ this.fieldScaleDeckIDField = value;}

}
[System.Xml.Serialization.XmlElementAttribute(Order = 9)]

public string WeighSlipNumber

{

get

{ return this.weighSlipNumberField; }

set

{ this.weighSlipNumberField = value; }

}
[System.Xml.Serialization.XmlElementAttribute(Order = 10)]

public string OriginatingScaleSiteNumber

{

get

{ return this.originatingScaleSiteNumberField; }

set

{ this.originatingScaleSiteNumberField = value; }

}
[System.Xml.Serialization.XmlElementAttribute(Order = 11)]

public string SplitLoad

{

get

{ return this.splitLoadField;}

set

{ this.splitLoadField = value;}

}
[System.Xml.Serialization.XmlElementAttribute(Order = 12)]

public string Beachcomb

{

get

{ return this.beachcombField;}

set

{ this.beachcombField = value;}

}

[System.Xml.Serialization.XmlElementAttribute(Order = 13)]

public string CheckScale

{

get

{ return this.checkScaleField;}

set

{this.checkScaleField = value;}

}

[System.Xml.Serialization.XmlElementAttribute(Order = 14)]

public string PSMeasure

{

get

{ return this.pSMeasureField; }

set

{ this.pSMeasureField = value; }

}
[System.Xml.Serialization.XmlAttributeAttribute()]

public string DDN

{

get

{ return this.dDNField; }

set

{ this.dDNField = value; }

}

[System.Xml.Serialization.XmlAttributeAttribute(Dat aType = "integer")]

public string DV

{

get

{ return this.dvField; }

set

{ this.dvField = value; }

}
// Somehow this ignore statement is removing other attributes not just this
attribute
// System.Xml.Serialization.XmlAttributeAttribute()

[System.Xml.Serialization.XmlIgnoreAttribute()]

public bool BeachcombSpecified

{

get

{ return this.beachcombFieldSpecified; }

set

{ this.beachcombFieldSpecified = value; }

}

public testClass()

{

EventType = "1";

PSCommon = "2";

LoadArrivalNumber = "3";

IncomingLDSNumber = "4";

TransportIdentifier = "5";

Source = "6";

CutblockID = "7";

FieldScaleFlag = "8";

FieldScaleDeckID = "9";

WeighSlipNumber = "10";

OriginatingScaleSiteNumber = "11";

SplitLoad = "12";

Beachcomb = "13";

CheckScale = "14";

PSMeasure = "15";

DDN = "16";

DV = "17";

BeachcombSpecified = false; //should be ignored

}
}
}

Here's the results

<?xml version="1.0" encoding="utf-8"?>

<testClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<EventType>1</EventType>

<PSCommon>2</PSCommon>

<LoadArrivalNumber>3</LoadArrivalNumber>

<IncomingLDSNumber>4</IncomingLDSNumber>

<TransportIdentifier>5</TransportIdentifier>

<Source>6</Source>

<CutblockID>7</CutblockID>

<FieldScaleFlag>8</FieldScaleFlag>

<FieldScaleDeckID>9</FieldScaleDeckID>

<WeighSlipNumber>10</WeighSlipNumber>

<OriginatingScaleSiteNumber>11</OriginatingScaleSiteNumber>

<SplitLoad>12</SplitLoad>

</testClass>

as you can see the last 5 fields did not make it to the XML.

If you simply comment out the

[System.Xml.Serialization.XmlIgnoreAttribute()]

public bool BeachcombSpecified

{

get

{ return this.beachcombFieldSpecified; }

set

{ this.beachcombFieldSpecified = value; }

}

and it's entry in the constructor

BeachcombSpecified = false; //should be ignored

they do make it

Once again this is done in the compact framework
Apr 11 '06 #1
2 3749
Hi Jamie,

Thanks for providing with us the code to repro this problem. Yes, I can
reproduce this on my machine. I will try to contact the product team on it
to see if we can get a workaround.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Apr 12 '06 #2
Hi Jamie,

This might be a bug in the compact framework. You can try to contact
Microsoft PSS for a workaround. Here is the contact information

http://support.microsoft.com/default...;OfferProPhone

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Apr 19 '06 #3

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

Similar topics

1
2701
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
2
3500
by: Dean A. Hoover | last post by:
I am attempting to parse an extremely simple xml file that has an embedded DTD using java sax2. Here is the xml file: <?xml version="1.0" ?> <!DOCTYPE foo > <foo> <bar/> </foo>
2
1138
by: Eric Smith | last post by:
I'm writing a DTD for a simulator to save the state of the simulated machine, such as register and memory contents. In this particular application, it is not expected that the generated XML will...
5
3831
by: WindAndWaves | last post by:
Greetings once more, I was wondering if someone figured out the difference between attributes and properties. I noticed that things like fields have a number of properties, but also...
5
2564
by: Mike | last post by:
Currently, when my application needs to write/read to a database, there is a time lag. In that time lag, a user can click the same button multiple times causing my app problems. I want to turn...
0
1123
by: Saradhi | last post by:
Hi All , I am using the Code model for Generating the VB code on the Fly. I am able to generate a new class with the Variables, Fields and Methods I want. Now What I want is the facility to...
6
1450
by: Jan Nielsen | last post by:
Hi all I have a typed dataset (vb.net) that the wizard created. I have a photo in the dataset that I do not want to get xml serialized. I use the function dataset.WriteXml() to serialize. It...
5
15965
by: s.luongo | last post by:
Hello everybody, Trying to get all attributes from a class (class1), I got them through properties, is it a simple way to get all class atributes not using their properties?? public void...
44
2884
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7017
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
7470
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...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.