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

In the following code, I try to read data from a plist: -(void)readPreferences {
I'm using the following code to try to read an input from user and
I have the following string read from an XML elememnt, and it is assigned
I am running the following code to try and read from a text file.
i try to read Data from an Oracle-Database. The problem is that in some
I try to read out all existing calendars. I tried the example from here:
I try to read file /proc/'pid'/status, using c program. The code is as follows,
When i try to read a JSON string like below it goes to endless
I see that when I try to read the value from a textarea field
I have a swing application that read HTML pages using the following command String

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.