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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:40:54+00:00 2026-06-11T01:40:54+00:00

i have a xml tag like : <p xmlns=http://www.w3.org/1999/xhtml>Text1<span title=instruction=componentpresentation,componentId=1234,componentTemplateId=1111>CPText2CP</span></p> If i have to

  • 0

i have a xml tag like :

<p xmlns="http://www.w3.org/1999/xhtml">Text1<span title="instruction=componentpresentation,componentId=1234,componentTemplateId=1111">CPText2CP</span></p>

If i have to replace the tag <span title="instruction=componentpresentation,componentId=1234,componentTemplateId=1111">CPText2CP</span> with

<componentpresentation componentID="1234" templateID="1111" dcpID="dcp1111_1234" dcplocation="/wip/data/pub60/dcp/txt/dcp1111_1234.txt">Text2</componentpresentation>

Is any possible way to acchive this, please give suggestion/changes.

EDIT

From the above tag can i take full <span></span> tag as a string with the text in between the tags.any suggestions.

  • 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-11T01:40:56+00:00Added an answer on June 11, 2026 at 1:40 am

    You can do it like this:

            string input = @"
                <p xmlns=""http://www.w3.org/1999/xhtml"">
                    Text1
                    <span title=""instruction=componentpresentation,componentId=1234,componentTemplateId=1111"">
                        CPText2CP
                    </span>
                </p>";
    
    
            XDocument doc = XDocument.Parse(input);
            XNamespace ns = doc.Root.Name.Namespace;
    
            // I don't know what filtering criteria you want to use to 
            // identify the element that you wish to replace,
            // I just searched by "componentId=1234" inside title attribute
            XElement elToReplace = doc
                .Root
                .Descendants()
                .FirstOrDefault(el => 
                    el.Name == ns + "span" 
                    && el.Attribute("title").Value.Contains("componentId=1234"));
    
            XElement newEl = new XElement(ns + "componentpresentation");
    
            newEl.SetAttributeValue("componentID", "1234");
            newEl.SetAttributeValue("templateID", "1111");
            newEl.SetAttributeValue("dcpID", "dcp1111_1234");
            newEl.SetAttributeValue("dcplocation", 
                "/wip/data/pub60/dcp/txt/dcp1111_1234.txt");
    
            elToReplace.ReplaceWith(newEl);
    

    Your needs may vary but the way to go would be to create XDocument or XElement, search through it to find elements that need to be replaced and then use ReplaceWith to replace them. Note that you have to take namespaces into consideration, otherwise elements won’t be retrieved.

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

Sidebar

Related Questions

So I have some XML in the following format: <somenode> <html xmlns=http://www.w3.org/1999/xhtml> <head> <title/>
I have an xml tag that needs to be formatted like so: <AddDealRequest xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
I have a XML Like this: <?xml version=1.0 encoding=utf-8?> <soap:Envelope xmlns:soap=http://www.w3.org/2003/05/soap-envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <soap:Body>
I have a xml file like this <?xml version=1.0 encoding=utf-8?> <ArrayOfOffice xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <Offices>
I have an xsd document that starts with: <?xml version=1.0 encoding=UTF-8?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema> <xs:import
<xsl:stylesheet xmlns=http://www.w3.org/1999/xhtml version=1.0 xmlns:ms=urn:schemas-microsoft-com:xslt xmlns:infoRequest=ControlSkin3 xmlns:xsl=http://www.w3.org/1999/XSL/Transform exclude-result-prefixes=xmlns> <xsl:output omit-xml-declaration=yes method=xml encoding=utf-8 /> I've got
I have input xml of the form <content xml:lang=en xmlns:w=http://www.w.com/sch/W> <w:firstRowHeader>true</w:firstRowHeader> <w:firstColumnHeader>true</w:firstColumnHeader> <w:customTable> <w:tableContent>
I have looked at the documentation here: http://docs.python.org/dev/library/xml.etree.elementtree.html#xml.etree.ElementTree.SubElement The parent and tag argument seems
Here is an example of the XQuery output that I get: <clinic> <Name xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>Healthy
So I have code that looks like this: content_url = 'http://auburn.craigslist.org/cpg/index.rss' doc = Nokogiri::XML(open(content_url))

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.