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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:48:50+00:00 2026-05-23T17:48:50+00:00

I need to manipulate a XML string. The string is this one : <div

  • 0

I need to manipulate a XML string.
The string is this one :

<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>

I thought I would convert it into a XmlDocument, but XmlDocument.LoadXml() throws an error about the “:” character ; it’s because of the fb:like:layout attribute.

What I need to do, is add an addthis:url attribute to the first element with a addthis_toolbox or addthis_button class.

I’m pretty confident that I can find the element with the correct class, but I’m not really confident that I can add a “composite” attribute like that… especially since I can’t even load the thing to a XmlDocument.

Did I miss something ? Is there a better/simpler way ?

Thanks

  • 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-23T17:48:51+00:00Added an answer on May 23, 2026 at 5:48 pm

    Provided XML isn’t well-formed, so you can’t manipulate it using XML parser.

    You can perform pre-processing of this text, so it becomes well-formed XML, then manipulate it as XML using XML engine.

    EDIT:

    Read: RegEx match open tags except XHTML self-contained tags

    But may be in your case usage of regex is most appropriate, if you structure of input HTML is regular, e.g.:

    You can use this regex

    (?x)
    (?<=<)[^>]*
    class="[^"]*
    \b(?:addthis_toolbox|addthis_button)\b
    [^"]*"
    [^>]*
    

    to find div class="addthis_toolbox addthis_default_style ", then replace this string, i.e.:

    string xml = @"<div class=""addthis_toolbox addthis_default_style "">
    <a class=""addthis_button_facebook_like"" fb:like:layout=""button_count""></a>
    <a class=""addthis_button_tweet""></a>
    <a class=""addthis_counter addthis_pill_style""></a>
    </div>
    ";
    
    const string Pattern = @"(?xs)
        (?<=<)([^>]*
        class=""[^""]*
        \b(?:addthis_toolbox|addthis_button)\b
        [^""]*"")
        [^>]*
    ";
    
    var result = Regex.Replace(xml, Pattern, "$0 addthis:url=\"value\"");
    

    Result:

    <div class="addthis_toolbox addthis_default_style " addthis:url="value">
    <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
    <a class="addthis_button_tweet"></a>
    <a class="addthis_counter addthis_pill_style"></a>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to manipulate an existing XML document, and create a new one from
What things do I need to consider when doing this: What to remove/manipulate/add Regards
I need manipulate left and right key on prototype, something like http://mangastream.com/
I have an XML file which will output a string: <mystring> <manipulate type=caps> <string>Hello
I'm using AJAX to receive an XML response, which I then need to manipulate.
I have some data that multiple Activities need to manipulate. Basically there is one
I need to manipulate 100,000 - 200,000 records. I am thinking of using LINQ
I need to manipulate large strings in Java (deleting and adding the deleted chars
I'm converting an existing program to C++ and here need to manipulate Sybase timestamps.
In the code shown below, I need to manipulate the time var in python

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.