locked
Replace xml namspaces with prefixes in a node RRS feed

  • Question

  • Hi,
     
    I need some help while serializing the xsd schema object into an XML. As my schema object is built by using different small schemas, while serializing my xml is containing all the namespcaes at the root node of each schema used in the XSD as shown below.

    <PersonalDetails xmlns=http://Source.Core.Schemas.PersonalDetails>
        <Name>Ravinder</Name>
        <Address xmlns="http://Source.Core.Schemas.Address">
                    <AddressLine1>ABCDEFGHIJKL</AddressLine1>
                    <City>Hyderabad</City>
         </Address>
        <MailingAddress xmlns="http://Source.Core.Schemas.MailingAddress">
                    <AddressLine1>ABCDEFGHIJKL</AddressLine1>
                    <City>Hyderabad</City>
        </MailingAddress>
    </PersonalDetails>

    But I need the xml in below format

    <ns0:PersonalDetails xmlns:ns0=http://Source.Core.Schemas.PersonalDetails 
                xmlns:ns1=http://Source.Core.Schemas.MailingAddress
                xmlns:ns2="http://source.core.schemas.address/">
        <Name>Ravinder</Name>
        <ns1:Address >
                    <AddressLine1>ABCDEFGHIJKL</AddressLine1>
                    <City>Hyderabad</City>
         </ns1:Address>
        <ns2:MailingAddress>
                    <AddressLine1>ABCDEFGHIJKL</AddressLine1>
                    <City>Hyderabad</City>
        </ns2:MailingAddress>
    </ns0:PersonalDetails>

    I'm using C# to serialize the xsd schema into an xml. Please let me know the logic to convert the xml into above format. I was using stringbuilder.replace to format the xml as shown above after serializing, but I think this is one of the werdiest way to format an XML. Any help would be appreciated. Thanks in advance.
    thanks
    Thursday, October 30, 2008 3:40 AM