none
How to remove namespace from xml? RRS feed

  • Question

  • Hi Team,

          I want to remove unnessary namespace from element. But i don't know how to remove it in C#. I hope someone can solve my problem.

    Here is my raw XML.

    <?xml version="1.0" encoding="UTF-8" standalone="no"?> <rsm:Invoice xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:rsm="http://www.ita.org/" xmlns:ccts="urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecification:2" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:2" xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:2" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ita.org/ Invoice_20.xsd"> <rsm:HeaderExchangedDocument> <ram:ID xmlns:ram="http://www.ita.org/">103004</ram:ID>

    <!-- Want to remove xmlns:ram=http://www.ita.org/ in ram:ID element--> <ram:TypeCode xmlns:ram="http://www.ita.org/">Invoice</ram:TypeCode> <ram:IssueDateTime xmlns:ram="http://www.ita.org/">2014-01-01</ram:IssueDateTime> <ram:CopyIndicator xmlns:ram="http://www.ita.org/">Original</ram:CopyIndicator> <ram:CustomsID xmlns:ram="http://www.ita.org/" /> <ram:HeaderInformation xmlns:ram="http://www.ita.org/" /> <ram:SummaryInformation xmlns:ram="http://www.ita.org/" /> </rsm:HeaderExchangedDocument> </rsm:Invoice>

    Require Output

    <?xml version="1.0" encoding="UTF-8"?>
    <rsm:Invoice xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:rsm="http://www.ita.org/" 
    xmlns:ccts="urn:un:unece:uncefact:documentation:standard:TechnicalSpecification:2" 
    xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:2" 
    xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:2" 
    xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.ita.org/ Invoice_20.xsd">
      <rsm:HeaderExchangedDocument>
        <ram:ID>103004</ram:ID>
        <ram:TypeCode>Invoice</ram:TypeCode>
        <ram:IssueDateTime>2014-01-01</ram:IssueDateTime>
        <ram:CopyIndicator>Original</ram:CopyIndicator>
        <ram:CustomsID/>
        <ram:HeaderInformation/>
        <ram:SummaryInformation/>
      </rsm:HeaderExchangedDocument>
    </rsm:Invoice>

    Best Regards,

    Yukon


    Make Simple & Easy

    Monday, November 5, 2012 9:17 AM

Answers

  • ok,

    then you can do this by reading XML data as string and replace element having namespace with same element without namespace.

    So it would be sort of manual removing via code behind.


    Sandy..

    Friday, November 16, 2012 11:39 AM

All replies