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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:42:20+00:00 2026-05-21T07:42:20+00:00

I have some xml that looks like this: <rootElement attribute=’ > ‘/> This is

  • 0

I have some xml that looks like this:

<rootElement attribute=' > '/>

This is accepted as well-formed xml by the parsers I’ve tried it on, and the relevant part of the RFC also suggests this is valid, although I personally wasn’t convinced it was until I checked (interestingly enough this wouldn’t be valid if it was a opening triangular brace, but it is as a closing brace).

I have some code that is used to “pretty print” xml – it should only change line-lengths and new lines – it shouldn’t change any content. However, no matter how I try to parse this xml, it always ends up being entity replaced:

<rootElement attribute=' &gt; '/>

This isn’t entirely unexpected, and any xml parser should treat the two as identical, but for my purposes I don’t want this behaviour as this is code meant to change the formatting of an xml file only, not its contents.

It doesn’t matter if I load my xml into an XmlDocument:

var xml = "<rootElement attribute=' > '/>";
var doc = new XmlDocument();
doc.LoadXml(xml);
Console.WriteLine(doc.OuterXml);

Or an XElement:

var xElement = XElement.Parse(xml);
xElement.Save(Console.Out);

Or pass it through a reader/writer pair:

using (var ms = new MemoryStream())
using (var streamWriter = new StreamWriter(ms))
{
    streamWriter.Write(xml);
    streamWriter.Flush();
    ms.Position = 0;

    using (var xmlReader = XmlReader.Create(ms))
    {
        xmlReader.Read();
        Console.WriteLine(xmlReader.ReadOuterXml());
    }
}

They all replace the > entity with a &gt;, event though the former is acceptable well-formed xml. I’ve tried playing with the various XmlReaderSettings, or XElement’s LoadOptions, etc, but all to no avail.

Does anyone know of any way to prevent this?

This is more of a curiosity than an actual issue, but I am interested to see if anyone has any solutions.

[EDIT to clarify, in the light of some comments/answers]

I really do realise that this behaviour is expected. In my case, maybe I don’t want to use one of the built in xml APIs at all (although whatever I use needs to understand the structure of xml so as not to line break in inappropriate places where it changes the semantic meaning of the document.)

I’m really just interested to know if anyone knows of a way to change the behaviour in these parsers (I expect you can’t but figured if anyone knew, they’d probably be on SO), or if anyone has any other 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-21T07:42:21+00:00Added an answer on May 21, 2026 at 7:42 am

    My guess is that you’ll find there isn’t a way to change this – as I strongly suspect that the internal representation after loading will be the same whether it’s originally > or &gt;.

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

Sidebar

Related Questions

I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
Grettings! I have some XML that looks like this: <Root> <SectionA> <Item id=111> <Options>
I have a function that loads in some XML that looks like this: private
Let's say I have some XML like this <channel> <item> <title>This is title 1</title>
Greetings! I have some XML like this: <Root> <AlphaSection> . . . </AlphaSection> <BetaSection>
Greetings! I have some XML like this: <Root> <MainSection> <SomeNode>Some Node Value</SomeNode> <SomeOtherNode>Some Other
I have a file which is an XML representation of some data that is
i have some xml with math ml inside, and i would like to find
I have some XML in an XmlDocument, and I want to display it on
So I have some XML in the following format: <somenode> <html xmlns=http://www.w3.org/1999/xhtml> <head> <title/>

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.