0

My XML having multiple namespaces. I want clean XML just with tags only. Here is my XML:

    <BizMsg xmlns="urn:asx:xsd:xasx.802.001.04" xmlns:xsi_0="http://www.w3.org/2001/XMLSchema-instance" xsi_0:schemaLocation="urn:asx:xsd:xasx.802.001.04 ASX_AU_CHS_comm_802_001_04_xasx_802_001_04.xsd">
      <AppHdr xmlns="urn:iso:std:iso:20022:tech:xsd:head.001.001.02" xmlns:xsi_1="http://www.w3.org/2001/XMLSchema-instance" xsi_1:schemaLocation="urn:iso:std:iso:20022:tech:xsd:head.001.001.02 ASX_AU_CHS_comm_801_001_02_head_001_001_02.xsd">
            <From>
            </From>
       </AppHdr>
  </BizMsg>

I am able to remove xmlns with this code:

public static XElement RemoveAllNamespaces(XElement e)
        {
            return new XElement(e.Name.LocalName,
               (from n in e.Nodes()
                select ((n is XElement) ? RemoveAllNamespaces(n as XElement) : n)),
               (e.HasAttributes) ? (from a in e.Attributes()
                                    where (!a.IsNamespaceDeclaration)
                                    select new XAttribute(a.Name.LocalName, a.Value)) : null);
        }

By applying this code I am getting schemaLocation in result, I want to get just tag only as result. Please advise.

    <BizMsg schemaLocation="urn:asx:xsd:xasx.802.001.04 ASX_AU_CHS_comm_802_001_04_xasx_802_001_04.xsd">
      <AppHdr schemaLocation="urn:iso:std:iso:20022:tech:xsd:head.001.001.02 ASX_AU_CHS_comm_801_001_02_head_001_001_02.xsd">
       <From>
       </From>
     </AppHdr>
   </BizMsg>

I want to get as result:

   <BizMsg>
      <AppHdr>
       <From>
       </From>
     </AppHdr>
   </BizMsg>
7
  • Please edit your question and add desired output. Commented Feb 23, 2022 at 3:00
  • @YitzhakKhabinsky added output. Commented Feb 23, 2022 at 3:03
  • Are you open to use XSLT? Commented Feb 23, 2022 at 3:05
  • If I can get the required output than it's okay to use. Commented Feb 23, 2022 at 3:06
  • 1
    Why do you want to remove XML namespaces? Your reference to "clean" XML (namespaces are not "unclean"), your confusion between namespaces and schemaLocation attributes, and your lack of any justifying motivation suggest that obliging your request may do more harm than good. XML namespaces play an important role in identifying XML components and should not be removed without understanding that role fully. Commented Feb 23, 2022 at 3:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.