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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:30:06+00:00 2026-06-14T11:30:06+00:00

I’m working on a C# application that pulls apart two Xml documents, merges some

  • 0

I’m working on a C# application that pulls apart two Xml documents, merges some of their tag content, and produces a third Xml document. I’m faced with a situation where I need to extract the value of one tag, including inner tags, and transfer it to another tag. I started out doing something like this:

var summaryElement = elementExternal.Element("summary");
var summaryValue = (string)summaryElement;
var summaryValueClean = ElementValueClean(summaryValue);

var result = new XElement("para", summaryValueClean)

Where the ElementValueClean function removes extraneous white space.

This works satisfactorily if the value of the summary tag contains only text. The rub comes when the summary tag contains child elements like:

<summary>
   Notifies the context that a new link exists between the <paramref name="source" /> and <paramref name="target" /> objects
   and that the link is represented via the source.<paramref name="sourceProperty" /> which is a collection.
   The context adds this link to the set of newly created links to be sent to
   the data service on the next call to SaveChanges().
</summary>

I would like to produce something like this:

<para>
Notifies the context that a new link exists between the <paramref name="source" /> and <paramref name="target" /> objects
and that the link is represented via the source.<paramref name="sourceProperty" /> which is a collection.
The context adds this link to the set of newly created links to be sent to
the data service on the next call to SaveChanges().
</para>

There are roughly a dozen possible embedded tags that could appear across my catalog of source tags whose content I must merge into output tags. So I would like a C# solution that I can generalize. However, an Xslt transform that I can apply to Xml fragment to produce the Xml fragment would work for me also if it is simple enough. My Xslt skills have diminished from disuse.

  • 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-06-14T11:30:08+00:00Added an answer on June 14, 2026 at 11:30 am

    You could update the ElementValueClean() function to support inline nodes and accept an Element instead of its string value:

    foreach (XmlNode n in summaryElement.Nodes()) {
      if (node.NodeType == XmlNodeType.Text) {
          //do text cleanup
      }
      else n
    }
    

    An XSLT to rewrap the element is really simple, but I think a C# solution still makes more sense because you already have a usable C# text cleanup solution.

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        exclude-result-prefixes="xs"
        version="2.0">
    
        <xsl:template match="summary">
            <para><xsl:apply-templates/></para>
        </xsl:template>
    
        <xsl:template match="node()|@*" priority="-1" mode="#default">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*" mode="#current"/>
            </xsl:copy>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Or you could do the whole thing in XSLT, including text cleanup. It’s not clear what that function does, but this is how you’d start it in XSLT:

    <xsl:template match="text()">
        <xsl:value-of select="normalize-space(.)"/>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.