XML is not formatting correctly from object class

17 Views Asked by At

I want to generate the XML output from my object class as per below xml, But when it is creating the xml Node <ns2:LoadStatusData is creating as <LoadStatusData ( ns2: ) is missing from the XML. Can you please suggest what i am doing mistake in my object class.

 <?xml version="1.0"?>
<ns2:LoadStatusData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ns2="http://schemas.3gtms.com/tms/v1/tns">
  <BatchInfo>
    <BatchNum>20230420175634</BatchNum>
    <BatchDateTime>2023-04-20T17:56:34.5647378+05:30</BatchDateTime>
    <SentBy>NIN-Integration</SentBy>
    <PageNum>0</PageNum>
    <PageCnt>0</PageCnt>
    <NullPrimaryEmptyElements>false</NullPrimaryEmptyElements>
  </BatchInfo>
</ns2:LoadStatusData>

For the same i have created object class as per below

[XmlRoot(ElementName="BatchInfo")]
public class BatchInfo { 

    [XmlElement(ElementName="BatchNum")] 
    public double BatchNum { get; set; } 

    [XmlElement(ElementName="BatchDateTime")] 
    public DateTime BatchDateTime { get; set; } 

    [XmlElement(ElementName="SentBy")] 
    public string SentBy { get; set; } 

    [XmlElement(ElementName="PageNum")] 
    public int PageNum { get; set; } 

    [XmlElement(ElementName="PageCnt")] 
    public int PageCnt { get; set; } 

    [XmlElement(ElementName="NullPrimaryEmptyElements")] 
    public bool NullPrimaryEmptyElements { get; set; } 
}

[XmlRoot(ElementName="LoadStatusData")]
public class LoadStatusData { 

    [XmlElement(ElementName="BatchInfo")] 
    public BatchInfo BatchInfo { get; set; } 

    [XmlAttribute(AttributeName="xsd")] 
    public string Xsd { get; set; } 

    [XmlAttribute(AttributeName="xsi")] 
    public string Xsi { get; set; } 

    [XmlAttribute(AttributeName="ns2")] 
    public string Ns2 { get; set; } 

    [XmlText] 
    public string Text { get; set; } 
}

Current XML is generating as below there (ns2:) is missing

<LoadStatusData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://schemas.3gtms.com/tms/v1/tns">
  <BatchInfo>
    <BatchNum>20230420181158</BatchNum>
    <BatchDateTime>2023-04-20T18:11:58.7330956+05:30</BatchDateTime>
    <SentBy>NIN-Integration</SentBy>
    <PageNum>0</PageNum>
    <PageCnt>0</PageCnt>
    <NullPrimaryEmptyElements>false</NullPrimaryEmptyElements>
  </BatchInfo>
</LoadStatusData>
0

There are 0 best solutions below