Remove xml null elements and attributes in soap body request using C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All,

I would like to remove nullable XML elements (where i:nil="true") in my soap body request by using C#.

My soap XML request looks like the following ..

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/
<s:Body>
<CreatePolicyRequest xmlns="http://www.sequel.com/services/UW/Policy/2011/12
<Policy xmlns:i="http://www.w3.org/2001/XMLSchema-instance
<PropertiesChanged i:nil="true" xmlns="" />
<ClassCodes i:nil="true" xmlns="" />
<Clients i:nil="true" xmlns="" />
<CompanyLeaders i:nil="true" xmlns="" />
<ConditionCodes i:nil="true" xmlns="" />
<ContractCertainty xmlns="
<PropertiesChanged>
<Property>ContractBasis</Property>
</PropertiesChanged>
<ContractBasis>Slip Policy</ContractBasis>
<PosBindContractCertaintyCheck i:nil="true" />
<PosBindDateTime i:nil="true" />
<PosBindUsername i:nil="true" />
<PreBindContractCertaintyCheck i:nil="true" />
<PreBindDateTime i:nil="true" />
<PreBindNotes i:nil="true" />
<PreBindUsername i:nil="true" />
<Slip i:nil="true" />
</ContractCertainty>
<CoverHolders i:nil="true" xmlns="" />
<Detail xmlns="
<PropertiesChanged>
<Property>AggRiskData</Property>
<Property>AnticipatedLR</Property>
</PropertiesChanged>
<AggLimit i:nil="true" />
<AggRiskData>Yes - Aggregates only</AggRiskData>
<AnticipatedLossRatio i:nil="true" />
<AnticipatedLR>0</AnticipatedLR>
<ZoneD i:nil="true" />
</Detail>
<Id xmlns=" 0</Id>
<Intermediares i:nil="true" xmlns="" />
<LinkedPolicy i:nil="true" xmlns="" />
<LloydsLeaders i:nil="true" xmlns="" />
<LossPayees i:nil="true" xmlns="" />
<OriginalId i:nil="true" xmlns="" />
<Placers xmlns="
<PolicyBroker>
<PropertiesChanged i:nil="true" />
<BrokerCode>0</BrokerCode>
<BrokerContactID i:nil="true" />
</PolicyBroker>
</Placers>
<PolicyBinder i:nil="true" xmlns="" />
<PolicyDeductions i:nil="true" xmlns="" />
<PolicyEndorsements i:nil="true" xmlns="" />
<PolicyId xmlns=" 0</PolicyId>
<PolicyLimits i:nil="true" xmlns="" />
<PolicyLines xmlns="
<PolicyLine>
<PropertiesChanged>
<Property>LineStatus</Property>
</PropertiesChanged>
<Id i:nil="true" />
<LineStatus>Incom</LineStatus>
<LloydsSynd i:nil="true" />
</PolicyLine>
</PolicyLines>
<PolicyLOCs i:nil="true" xmlns="" />
<PolicyNotes xmlns="
<PolicyNote>
<PropertiesChanged i:nil="true" />
<Id i:nil="true" />
<Notes i:nil="true" />
<NoteType i:nil="true" />
<OriginalId i:nil="true" />
<PolicyNoteId i:nil="true" />
</PolicyNote>
</PolicyNotes>
<PolicyPremDetail i:nil="true" xmlns="" />
<PolicyPremiums xmlns="" />
<PolicyQuoteClauses i:nil="true" xmlns="" />
<PolicyQuotes i:nil="true" xmlns="" />
<PolicyUWInfos i:nil="true" xmlns="" />
<Producers i:nil="true" xmlns="" />
<PRIs i:nil="true" xmlns="" />
<ReAssured i:nil="true" xmlns="" />
<Retailers i:nil="true" xmlns="" />
<RiskCodes i:nil="true" xmlns="" />
<ThirdPartyAdmin i:nil="true" xmlns="" />
<TrustFundCodes i:nil="true" xmlns="" />
</Policy>
</CreatePolicyRequest>
</s:Body>
</s:Envelope>




I would like to change the above request to this format ...

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/
<s:Body>
<CreatePolicyRequest xmlns="http://www.sequel.com/services/UW/Policy/2011/12
<Policy xmlns:i="http://www.w3.org/2001/XMLSchema-instance
<ContractCertainty xmlns="
<PropertiesChanged>
<Property>ContractBasis</Property>
</PropertiesChanged>
<ContractBasis>Slip Policy</ContractBasis>
</ContractCertainty>
<Detail xmlns="
<PropertiesChanged>
<Property>AggRiskData</Property>
<Property>AnticipatedLR</Property>
</PropertiesChanged>
<AggRiskData>Yes - Aggregates only</AggRiskData>
<AnticipatedLR>0</AnticipatedLR>
</Detail>
<Id xmlns=" 0</Id>
<Placers xmlns="
<PolicyBroker>
<BrokerCode>0</BrokerCode>
</PolicyBroker>
</Placers>
<PolicyId xmlns=" 0</PolicyId>
<PolicyLines xmlns="
<PolicyLine>
<PropertiesChanged>
<Property>LineStatus</Property>
</PropertiesChanged>
<LineStatus>Incom</LineStatus>
</PolicyLine>
</PolicyLines>
<PolicyNotes xmlns="
<PolicyNote>
</PolicyNote>
</PolicyNotes>
</Policy>
</CreatePolicyRequest>
</s:Body>
</s:Envelope>
Any response would be appreciated.
Thanks,
Prav

View the full article
 

Similar threads

W
Replies
0
Views
1,617
WRBehning
W
I
Replies
0
Views
69
Intermediate-User
I
B
Replies
0
Views
104
Born2Achieve
B
Back
Top