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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:51:12+00:00 2026-05-16T15:51:12+00:00

I have a simple xml node inside an xml document in C# that I

  • 0

I have a simple xml node inside an xml document in C# that I would like to query, then set the value for the visible attribute to false. Below is the xml. I need to be able to select the node by the node name(DGField) and the text_id(Test.ChangeRank). Does anyone know how to do this? Thanks in advance.

<DGField text_id="Test.ChangeRank" template="Ranking" visible="true">
  • 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-16T15:51:12+00:00Added an answer on May 16, 2026 at 3:51 pm

    Assuming your XmlDocument is called doc, then the following should work.

      XmlNode node = doc.SelectSingleNode("//DGField[@text_id='Test.ChangeRank']");
      if (node != null)
      {
        node.Attributes["visible"].Value = "false";
      }
    

    This could do with more error checking to ensure the attribute being changed exists etc. but this keeps it clean.

    Basically the first line uses an XPath expression to locate a DGField element where text_id=’Test.ChangeRank’. If found then node is returned and then used to manipulate the desired attribute value.

    I used the ‘//’ syntax in the XPath query so that the entire Xml document is searched, this is not optimal, being more specific with the XPath can perform better. For example if you had a complete document that looked something like this

    <root>
      <DGFields>
        <DGField text_id='1' template='Ranking' visible='true' />
        <DGField text_id='Test.ChangeRank' template='Ranking' visible='true' />
      </DGFields>
    </root>
    

    Then a more specific XPath query can be used like the following

    XmlNode node = doc.SelectSingleNode(
      "root/DGFields/DGField[@text_id='Test.ChangeRank']");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple xml file that I'm looping over to set a ValueObject
I have a simple XML document that I want to read into an object
I have the following simple XML structure that has to be parsed: <Nodes> <Node
I have a simple XML and i signed the XML using XPATH query like
Situation: I have a simple XML document that contains image information. I need to
I have a simple class that I trying to populate from an XML document.
I have a simple Xml Node that I need to recreate <Division ID=123>Division Name</Division>
I have very simple xml <root> <node>some value</node> </root> How can I get the
I have a simple XML extraction issue that should be solvable with straight PHP
i have a simple xml file in a wcf service that i am trying

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.