How To Set XmlElementAttruibute Value While Using XmlSerializer (C#)

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have generated CS classes from an Xml schema using xsd.exe. I now have the following class where I cannot figure out how to set the value of the attributes DUNS, DUNSPlus4, etc.

<div style="color:Black; background-color:White
<pre>[System.CodeDom.Compiler.GeneratedCodeAttribute(<span style="color:#a31515 "xsd"
, <span style="color:#a31515 "2.0.50727.42"
)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(<span style="color:#a31515 "code"
)]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = <span style="color:#a31515 "urn:rosettanet:specification:universal:PartnerIdentification:xsd:schema:01.06"
)]
[System.Xml.Serialization.XmlRootAttribute(<span style="color:#a31515 "PartnerIdentification"
, Namespace = <span style="color:#a31515 "urn:rosettanet:specification:universal:PartnerIdentification:xsd:schema:01.06"
, IsNullable = <span style="color:Blue false
)]
<span style="color:Blue public
<span style="color:Blue partial
<span style="color:Blue class
PartnerIdentificationType : IdentifierType
{

<span style="color:Blue private
<span style="color:Blue string
partnerNameField;

<span style="color:Blue private
<span style="color:Blue object
[] itemsField;

<span style="color:Blue private
ItemsChoiceType1[] itemsElementNameField;

<span style="color:Gray ///
<span style="color:Gray <remarks/>

<span style="color:Blue public
<span style="color:Blue string
PartnerName
{
<span style="color:Blue get

{
<span style="color:Blue return
<span style="color:Blue this
.partnerNameField;
}
<span style="color:Blue set

{
<span style="color:Blue this
.partnerNameField = value;
}
}

<span style="color:Gray ///
<span style="color:Gray <remarks/>

[System.Xml.Serialization.XmlElementAttribute(<span style="color:#a31515 "DUNS"
, <span style="color:Blue typeof
(<span style="color:Blue string
), Namespace = <span style="color:#a31515 "urn:rosettanet:specification:universal:DataType:xsd:schema:01.03"
)]
[System.Xml.Serialization.XmlElementAttribute(<span style="color:#a31515 "DUNSPlus4"
, <span style="color:Blue typeof
(<span style="color:Blue string
), Namespace = <span style="color:#a31515 "urn:rosettanet:specification:universal:DataType:xsd:schema:01.03"
)]
[System.Xml.Serialization.XmlElementAttribute(<span style="color:#a31515 "GLN"
, <span style="color:Blue typeof
(<span style="color:Blue string
), Namespace = <span style="color:#a31515 "urn:rosettanet:specification:universal:DataType:xsd:schema:01.03"
)]
[System.Xml.Serialization.XmlElementAttribute(<span style="color:#a31515 "AlternativeIdentifier"
, <span style="color:Blue typeof
(AlternativeIdentifierType), Namespace = <span style="color:#a31515 "urn:rosettanet:specification:universal:Locations:xsd:schema:01.03"
)]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute(<span style="color:#a31515 "ItemsElementName"
)]
<span style="color:Blue public
<span style="color:Blue object
[] Items
{
<span style="color:Blue get

{
<span style="color:Blue return
<span style="color:Blue this
.itemsField;
}
<span style="color:Blue set

{
<span style="color:Blue this
.itemsField = value;
}
}

<span style="color:Gray ///
<span style="color:Gray <remarks/>

[System.Xml.Serialization.XmlElementAttribute(<span style="color:#a31515 "ItemsElementName"
)]
[System.Xml.Serialization.XmlIgnoreAttribute()]
<span style="color:Blue public
ItemsChoiceType1[] ItemsElementName
{
<span style="color:Blue get

{
<span style="color:Blue return
<span style="color:Blue this
.itemsElementNameField;
}
<span style="color:Blue set

{
<span style="color:Blue this
.itemsElementNameField = value;
}
}
}
[/code]


I thought that I should be setting the value somewhere inside the object array "Items" but I have not been able to figure this out.

<div style="color:Black; background-color:White
<pre>PartnerIdentification = <span style="color:Blue new
PartnerIdentificationType()
{
PartnerName = results[2],
Items = <span style="color:Blue new
<span style="color:Blue object
[]
{
<span style="color:Green //DUNS

<span style="color:Green //DUNSPlus4

<span style="color:Green //GLN

<span style="color:Green //AlternativeIdentifier

<span style="color:Green //ItemsElementName

},
ItemsElementName = <span style="color:Blue new
ItemsChoiceType1[]
{
<span style="color:Blue new
ItemsChoiceType1()
{
}
}
},
schemaVersion = schemaVer
[/code]

Any help would be appreciated.


View the full article
 
Back
Top