Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:54:52+00:00 2026-06-08T18:54:52+00:00

I have some legacy XML documents stored in a database as a blob, which

  • 0

I have some legacy XML documents stored in a database as a blob, which are not well formed XML. I’m reading them in from a SQL database, and ultimately, as I am using C#.NET, would like to instantiate them as an XMLDocument.

When I try to do this, I obviously get an XMLException. Having looked at the XML documents, they are all failing because of undeclared namespaces in specific XML Nodes.

I am not concerned with any of the XML nodes which have this prefix, so I can ignore them or throw them away. So basically, before I load the string as an XMLDocument, I would like to remove the prefix in the string, so that

<tem:GetRouteID>
        <tem:PostCode>postcode</tem:PostCode>
        <tem:Type>ItemType</tem:Type>
</tem:GetRouteID>

becomes

<GetRouteID>
    <PostCode>postcode</PostCode>
    <Type>ItemType</Type>
</GetRouteID>

and this

<wsse:Security soapenv:actor="">
    <wsse:BinarySecurityToken>token</wsse:BinarySecurityToken>
</wsse:Security>

becomes this :

<Security soapenv:actor="">
    <BinarySecurityToken>token</BinarySecurityToken>
</Security>

I have one solution which does this like so :

<appSettings>
  <add key="STRIP_NAMESPACES" value="wsse;tem" />
</appSettings>
if (STRIP_NAMESPACES != null)
{
    string[] namespaces = Regex.Split(STRIP_NAMESPACES, ";");

    foreach (string ns in namespaces)
   {
        str2 = str2.Replace("<" + ns + ":", "<"); // Replace opening tag
        str2 = str2.Replace("</" + ns + ":", "</"); // Replace closing tag

    }
}

but Ideally I would like a generic approach for this, so I don’t have to endlessly configure the namespaces I want to remove.

How can I achieve this in C#.NET. I am assuming that a Regex is the way to go here?

UPDATE 1

Ria’s Regex below works well for the requirement above. However, how would I need to change the Regex to also change this

<wsse:Security soapenv:actor="">
    <BinarySecurityToken>authtoken</BinarySecurityToken>
</Security>

to this?

<Security>
    <BinarySecurityToken>authtoken</BinarySecurityToken>
</Security>

UPDATE 2

Think I’ve worked out the updated version myself based on Ria’s answer like so :

<(/?)\w+:(\w+/?) ?(\w+:\w+.*)?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:54:55+00:00Added an answer on June 8, 2026 at 6:54 pm

    UPDATE

    For new issue (attribs namespace) try this general solution. this has no effect on node values:

    Regex.Replace(originalXml, 
                  @"((?<=</?)\w+:(?<elem>\w+)|\w+:(?<elem>\w+)(?==\"))", 
                  "${elem}");
    

    try this regex on my sample xml:

    <wsse:Security soapenv:actor="dont match soapenv:actor attrib">
        <BinarySecurityToken>authtoken</BinarySecurityToken>
    </Security> 
    

    Try using XSL, You can apply XSL directly or using XslTransform class in .NET:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="no"/>
    
    <xsl:template match="/|comment()|processing-instruction()">
        <xsl:copy>
          <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="*">
        <xsl:element name="{local-name()}">
          <xsl:apply-templates select="@*|node()"/>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="@*">
        <xsl:attribute name="{local-name()}">
          <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>
    </xsl:stylesheet>
    

    or try this Regex:

    var finalXml = Regex.Replace(originalXml, @"<(/?)\w+:(\w+/?)>", "<$1$2>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some non-standard XML from a legacy app: <PODRoot> <RowData> <PODItem>Item243</PODItem> <StoragePath>PODItem66</StoragePath> <ID>-13</ID>
I have some legacy SQL (SP) declare @FactorCollectionId int; select @FactorCollectionId = collectionID from
I need to integrate some legacy 32-bit code - for which I don't have
Currently I have some legacy ASP.NET 2.0 code that uses the ASP Xml web
I have an xml string saved in a legacy database that I'm attempting to
I have a legacy file format which I'm converting into XML for processing. The
I have some legacy XSLT scripts that incorporate VBScript in them. They are run
We have some legacy code that needs to identify in the Page_Load which event
We have some legacy ASP.NET code that detects if a request is secure, and
I have some legacy code that was used to monitor my applications cpu,memory etc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.