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 7597289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:07:20+00:00 2026-05-30T22:07:20+00:00

Using the .Net framework, I need to read XML entity text as raw string

  • 0

Using the .Net framework, I need to read XML entity text as raw string values (character entities not expanded) for use in a comparison / merge function. As far as I can tell, there’s no way of directly turning off character entity expansion.

I’ve tried deriving from XmlTextReader and hooking the Read() method, which does intercept reads, but the Value property is read-only and I can’t see any way of modifying the incoming text:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace blah {
    class XmlRawTextReader : XmlTextReader {
        public XmlRawTextReader(string fileName) : base(fileName) { }

        public override bool Read() {
            bool result = base.Read();
            if (result == true && base.HasValue && base.NodeType == XmlNodeType.Text) {
                string s = this.Value;
                //this.Value = @"new value";  // does not work - read-only
            }
            return result;
        }
    }
}

Does anyone know how to either disable character entity expansion or updating strings at the point they’re read?

Kinda stuck here so thanks in advance for ideas…

  • 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-30T22:07:22+00:00Added an answer on May 30, 2026 at 10:07 pm

    After putting this on the back-burner for a while, the answer became apparent:

    Although you can’t easily override the Read() method to change the read value, you can hook the property accessor to do the same thing:

    using System;
    using System.Collections.Generic;
    using System.Xml;
    
    namespace blah {
    
        class XmlCustomTextReader : XmlTextReader {
    
            private Func<string, List<KeyValuePair<string, string>>, string> _updateFunc;
    
            public XmlCustomTextReader(string fileName, Func<string, List<KeyValuePair<string, string>>, string> updateFunc = null) : base(fileName) {
                _updateFunc = updateFunc;
            }
    
            //
            // intercept and override value access - 'un-mangle' strings that were rewritten by XMLTextReader
            public override string Value {
                get {
                    string currentvalue = base.Value;
    
                    // only text nodes
                    if (NodeType != XmlNodeType.Text)
                        return currentvalue;
    
                    string newValue = currentvalue;
    
                    // if a conversion function was provided, use it to update the string
                    if (_updateFunc != null)
                        newValue = _updateFunc(currentvalue, null);
    
                    return newValue;
                }
            }
        }
    }
    

    Use this by:

            Func<string, List<KeyValuePair<string, string>>, string> updateFunc = UpdateString;
            XmlCustomTextReader reader = new XmlCustomTextReader(fileName, updateFunc);
            reader.XmlResolver = new XmlCustomResolver(XmlCustomResolver.ResolverType.useResource);
            XDocument targetDoc = XDocument.Load(reader);
    

    I hope this helps someone in the future…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C# and the .Net framework 2.0. I have an MDI application and need
I'm developing an application targeting .NET Framework 2.0 using C# for which I need
Using the .NET framework, I'm trying to replace double slash characters in a string
I am using the .NET 2.0/3.5 framework for my application. I need to run
I'm writing out some xml from C# using the .net framework's XmlTextWriter. This works
I have read a bit about ADO.NET Entity Framework, but there is some things
I've an .NET app using Entity Framework 4 and SQL Server 2008 R2, where
I am using .Net framework 2.0 / jQuery to make an Ajax call to
What is difference in developing applications using .Net Framework, Asp.net and developing application in
I am trying to leverage ORM given the following requirements: 1) Using .NET Framework

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.