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

  • SEARCH
  • Home
  • 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 1033619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:15:33+00:00 2026-05-16T14:15:33+00:00

I am try to read the following string, captured from a log4net UdpAppender. <log4net:event

  • 0

I am try to read the following string, captured from a log4net UdpAppender.

<log4net:event logger="TestingTransmitter.Program" 
               timestamp="2009-08-02T17:50:18.928+01:00" 
               level="ERROR" 
               thread="9" 
               domain="TestingTransmitter.vshost.exe" 
               username="domain\user">
    <log4net:message>Log entry 103</log4net:message>
    <log4net:properties>
        <log4net:data name="log4net:HostName" value="machine" />
    </log4net:properties>
</log4net:event>

When trying to XElement.Parse or XDocument.Parse the content, it throws an exception:

‘log4net’ is an undeclared namespace.
Line 1, position 2.

I know I can search and replace “log4net:” in the original string and remove it, allowing me to parse the XML successfully, but is there a better way? This is the complete data captured (reformatted to allow reading), there are no xml namespace declarations made or removed..

  • 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-05-16T14:15:34+00:00Added an answer on May 16, 2026 at 2:15 pm

    First, create an instance of XmlNamespaceManager class, and add your namespaces to that, e.g.

        XmlNamespaceManager mngr = new XmlNamespaceManager( new NameTable() );
        mngr.AddNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
        mngr.AddNamespace( "xsd", "http://www.w3.org/2001/XMLSchema" );
    

    To parse an XML string using those namespace mappings, call the following function, passing the instance of XmlNamespaceManager with the namespaces you’ve added to it:

    /// <summary>Same as XElement.Parse(), but supports XML namespaces.</summary>
    /// <param name="strXml">A String that contains XML.</param>
    /// <param name="mngr">The XmlNamespaceManager to use for looking up namespace information.</param>
    /// <returns>An XElement populated from the string that contains XML.</returns>
    public static XElement ParseElement( string strXml, XmlNamespaceManager mngr )
    {
        XmlParserContext parserContext = new XmlParserContext( null, mngr, null, XmlSpace.None );
        XmlTextReader txtReader = new XmlTextReader( strXml, XmlNodeType.Element, parserContext );
        return XElement.Load( txtReader );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to try to read the results of a df
When I try to use curl or file_get_contents to read something like http://example.com/python/json/ from
Did anyone try to read programmatically an Alibre Design CAD file? I see that
fopen is failing when I try to read in a very moderately sized file
I have a very big file 4GB and when I try to read it
I am using the simple modal and Ajax . When I try to read
I have an app.config file inside my TestProject, but when I try to read
I try Request.Form.Set(k, v) but it's throwing exception Collection is read-only
try { ... } catch (SQLException sqle) { String theError = (sqle).getSQLState(); ... }
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error

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.