0
<sendSms xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://service.emay.com/">
    <CommonHeader>
        <batchNum>abc</batchNum> 
        <esbMsgID /> 
        <reqStartTime>abc</reqStartTime> 
        <reqEndTime>date</reqEndTime> 
    </CommonHeader>
    <BizBody>
        <record>
            <smsAccount>abc-abc-abc-abc</smsAccount> 
            <pwd /> 
            <deptID /> 
            <deptName /> 
            <phoneNum>1asd</phoneNum>  
            <customer>abc</customer> 
            <contract>abc</contract> 
            <smsType /> 
            <systemID>abc</systemID> 
            <signType>abc</signType> 
            <smsContent>abc/abc+abc+abc</smsContent> 
        </record>
    </BizBody>
</sendSms>

However the requirement is to have something like below XML

<wstxns1:sendSms xmlns:wstxns1="Some URL">
<CommonHeader>
    <batchNum>CAP20151207160553</batchNum>
    <esbMsgID></esbMsgID>
    <reqStartTime>2012-07-07 07:07:07</reqStartTime>
    <reqEndTime>2012-07-07 07:07:07</reqEndTime>
</CommonHeader>
<BizBody>
    <record>
        <smsAccount>短信帐号</smsAccount>
        <pwd>帐号密码</pwd>
        <deptID>部门编号</deptID>
        <deptName>部门名称</deptName>
        <phoneNum>手机号</phoneNum>
        <customer>客户名</customer>
        <contract>合同号</contract>
        <smsType>短信类型编码</smsType>
        <systemID>业务系统编码</systemID>
        <signType>企业签名类型</signType>
        <smsContent>短信内容</smsContent>
    </record>
</BizBody>
</wstxns1:sendSms>

As you guys can see that the difference is only XML prefix "wstxns1", how can we achieve this task and replace parent node by desired node. Rest of the XML (child nodes) seems fine.

  • It is easier to correct existing code. Can you add the code where you serialize xml now? For general answer, look at [msdn](https://msdn.microsoft.com/en-us/library/bb387075.aspx). – Sinatr Apr 11 '16 at 12:48
  • XmlSerializer xsSubmit = new XmlSerializer(typeof(sendSms), "http://service.emay.com/"); //XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); //ns.Add("", ""); System.IO.StringWriter sww = new System.IO.StringWriter(); XmlWriter writer = XmlWriter.Create(sww, new XmlWriterSettings { OmitXmlDeclaration = true }); //xsSubmit.Serialize(writer, objRequest, ns); xsSubmit.Serialize(writer, objRequest); return sww; – Atif Imtiaz Apr 11 '16 at 13:06
  • 2
    You can [edit](http://stackoverflow.com/posts/36549080/edit) your own question (and delete own comments). – Sinatr Apr 11 '16 at 13:08
  • I guess this will do what you want: http://stackoverflow.com/questions/2500111/how-do-i-add-a-default-namespace-with-no-prefix-using-xmlserializer – W van Noort May 09 '16 at 17:34

0 Answers0