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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:32:36+00:00 2026-06-04T02:32:36+00:00

So I’m looking for a way to edit individual element descriptions in an XML

  • 0

So I’m looking for a way to edit individual element descriptions in an XML file.

For example, say I have:

1  <stack id ="1">Stack1</stack>
2  <book id="EG-FE">This Book</book>
3  <book id="EG-FF">That Book</book>
4  <book id="FE-GT">Another Book</book>
5  <book id="JL-01">Invalid Book Id</book>
6  <stack id="2">Stack2</stack>

You’ll notice the book on line 5 has an odd format… the second part of the id (after the ‘-‘) has numbers where the rest of them have letters. How would I go about removing just the ‘-01’ part of the id of book 5 (I.e. change it to:

5  <book id="JL">Valid Book Id</book>

without modifying eny other elements? (I.E. stack)

Here is what I’m trying:

using System.Xml.Linq

XElement books = XElement.Load("{file}");

string _Attribute;
foreach (var bookID in books.Nodes()) 
{
    if(bookID.Attribute("book") )
    {
        _Attribute = bookID.Attribute("book")
        if(!Regex.IsMatch(_Attribute., @"^[a-zA-Z-]+$");
        {
            Regex.Replace(_Attribute, @"\d", "");
        }
        bookID.Attribute("book") = _Attribute;
    }
}

Obviously, this is horribly wrong… Any ideas on how to fix it?

Thank you!

I haven’t found much help dealing directly with this problem, and the bits and pieces I’m trying to put together aren’t really helping.

  • 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-04T02:32:38+00:00Added an answer on June 4, 2026 at 2:32 am
    using System.Xml.Linq
    
    XElement books = XElement.Load("{file}");
    
    string _Attribute;
    foreach (var bookID in books.Elements("book")) 
    {
        if(bookID.Attribute("id") != null)
        {
            _Attribute = bookID.Attribute("book").Value;
            if(!Regex.IsMatch(_Attribute, @"-[0-9]+$"))
            {
                Regex.Replace(_Attribute, @"-[0-9]+$", "");
            }
            bookID.Attribute("id").Value = _Attribute;
        }
    }
    

    Untested and all those usual comments. Fixed some of your assumptions about how Linq to XML works, and made the Regex check see if it ends in a digit and replace the final digits in that case.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.