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

  • Home
  • SEARCH
  • 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 1082891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:21:45+00:00 2026-05-16T22:21:45+00:00

My plan is to read in an XML document using my C# program, search

  • 0

My plan is to read in an XML document using my C# program, search for particular entries which I’d like to change, and then write out the modified document. However, I’ve become unstuck because it’s hard to differentiate between elements, whether they start or end using XmlTextReader which I’m using to read in the file. I could do with a bit of advice to put me on the right track.

The document is a HTML document, so as you can imagine, it’s quite complicated.

I’d like to search for an element id within the HTML document, so for example look for this and change the src;

<img border="0" src="bigpicture.png" width="248" height="36" alt="" id="lookforthis" />
  • 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-16T22:21:46+00:00Added an answer on May 16, 2026 at 10:21 pm

    If it’s actually valid XML, and will easily fit in memory, I’d choose LINQ to XML (XDocument, XElement etc) every time. It’s by far the nicest XML API I’ve used. It’s easy to form queries, and easy to construct new elements too.

    You can use XPath where that’s appropriate, or the built-in axis methods (Elements(), Descendants(), Attributes() etc). If you could let us know what specific bits you’re having a hard time with, I’d be happy to help work out how to express them in LINQ to XML.

    If, on the other hand, this is HTML which isn’t valid XML, you’ll have a much harder time – because XML APIs generalyl expect to work with valid XML documents. You could use HTMLTidy first of course, but that may have undesirable effects.

    For your specific example:

    XDocument doc = XDocument.Load("file.xml");
    foreach (var img in doc.Descendants("img"))
    {
        // src will be null if the attribute is missing
        string src = (string) img.Attribute("src");
        img.SetAttributeValue("src", src + "with-changes");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I plan to serialize a Django model to XML when it's saved or updated.
I'm contemplating the idea of implementing a XML translator using a compiler generator, based
Hello all I'm using NSXMLParser to parse some xml data. I'm using this data
I plan to create a logging/tracing mechanism, which writes the address ( const char*
I plan to be storing all my config settings in my application's app.config section
We plan to redesign, improve our (C#) application architecture. Anyone has some framework, hompage
I plan to use PyInstaller to create a stand-alone python executable. PythonInstaller comes with
I plan to have 2 projects. 1. mbtech.crm.mvc 2. mbtech.crm.tests I will have a
I plan to use a distributed cache in my load-balanced webapp. So I'm going
Overall Plan Get my class information to automatically optimize and select my uni class

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.