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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:00:06+00:00 2026-05-10T19:00:06+00:00

I have some code which returns InnerXML for a XMLNode. The node can contain

  • 0

I have some code which returns InnerXML for a XMLNode.

The node can contain just some text (with HTML) or XML.

For example:

<XMLNode>     Here is some &lt;strong&gt;HTML&lt;/strong&gt; <XMLNode> 

or

<XMLNode>     <XMLContent>Here is some content</XMLContnet> </XMLNode> 

if I get the InnerXML for <XmlNode> the HTML tags are returned as XML entities.

I cannot use InnerText because I need to be able to get the XML contents. So all I really need is a way to un-escape the HTML tags, because I can detect if it’s XML or not and act accordingly.

I guess I could use HTMLDecode, but will this decode all the XML encoded entities?

Update: I guess I’m rambling a bit above so here is a clarified scenario:

I have a XML document that looks like this:

<content id='1'>     <data>&lt;p&gt;A Test&lt;/p&gt;</data> </content id='2'> <content>     <data>         <dataitem>A test</dataitem>     </data> </content> 

If I do:

XmlNode xn1 = document.SelectSingleNode('/content[@id=1]/data'); XmlNode xn2 = document.SelectSingleNode('/content[@id=2]/data');  Console.WriteLine(xn1.InnerXml); Console.WriteLine(xn2.InnerXml);     

xn1 will return

 &lt;p&gt;A Test&lt;/p&gt; 

xn2 will return <dataitem>A test</dataitem>

I am already checking to see if what is returned is XML (in the case of xn2) so all I need to do is un-escape the &lt; etc in xn1.

HTMLDecode does this, but I’m not sure it would work for everything. So the question remains would HTMLDecode handle all the possible entities or is there a class somewhere that will do it for me.

  • 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. 2026-05-10T19:00:07+00:00Added an answer on May 10, 2026 at 7:00 pm

    I think Tomalak is on the right track, but I’d write the code a little differently:

            XmlNode xn = document.SelectSingleNode('/content[@id=1]/data');         if (xn.ChildNodes.Count != 1)         {             throw new InvalidOperationException('I don't know what to do if there's not exactly one child node.');         }         XmlNode child = xn.ChildNodes[0];         switch (child.NodeType)         {             case XmlNodeType.Element:                 Console.WriteLine(xn.InnerXml);                 break;             case XmlNodeType.Text:                 Console.WriteLine(xn.Value);                 break;             default:                 throw new InvalidOperationException('I can only handle elements and text nodes.');         } 

    This code makes a lot of your implicit assumptions explicit, and when you encounter data that’s not in the form you expect, it will tell you why it failed.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This thread on SO will probably help you decide: What… May 11, 2026 at 11:46 pm
  • Editorial Team
    Editorial Team added an answer Use Message Contracts when you need more control. In particular,… May 11, 2026 at 11:46 pm
  • Editorial Team
    Editorial Team added an answer using yui solution is quite tricky :) but below is… May 11, 2026 at 11:46 pm

Related Questions

I have some code in C# which has a com wrapper. This com wrapper
I have some code which I did not originally create that uses _beginthreadex and
I have some JS code which generates the following object, return { type: some
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.