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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:50:59+00:00 2026-05-19T05:50:59+00:00

I want to retrieve all the RULE nodes that have one or more attributes

  • 0

I want to retrieve all the RULE nodes that have one or more attributes that contains a given string. Once i found them I need to replace the string with a new one.
I tested those XPath query but they do not work:

string xpathquery = "/FIREWALL/ETH/RULE[contains(@*,'" + toTest + "')]"; //DOES NOT WORK
string xpathquery = "/FIREWALL/ETH/RULE[contains(attribute::*,'" + toTest +"')]"; //DOES NOT WORK

The strange thing is that if I use @attributename or attribute::attributename it actually works. Where is the error?

I am using the contains function because there could be two different cases, let’s say I want to replace $HOST1 with $HOST2:

<RULE .... host="$HOST1"/> //NO PROBLEM
<RULE .... host="$HOST1:21"/> //I NEED TO REPLACE ONLY $HOST1, NOT THE ENTIRE STRING

I can’t just set the Value attribute of XmlNode but I need to modify the string. Actually I don’t know if XPath can handle this with a find and replace or something like this.

  • 1 1 Answer
  • 4 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-19T05:51:00+00:00Added an answer on May 19, 2026 at 5:51 am

    The query you’re using checks the concatenated text of all the attributes. The correct syntax is:

    string xpathquery = "/FIREWALL/ETH/RULE/@*[contains(.,'" + toTest + "')]/..";
    

    In other words, find a matching attribute and return its parent element. Of course, if what you want to do is to work with the attribute values, you can dispense with the /.. on the end, in which case you’ll be returned the actual attribute nodes and can just iterate through them modifying the values accordingly.

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

Sidebar

Related Questions

Given the date, 2009/04/30, in one of the rows I want to retrieve all
I want to retrieve all records from one table when there are no matches
I want to retrieve all objects (not DOM elements) of a given type created
I want to retrieve declared SVG attributes programmatically. It's all inline content, something like
I want to retrieve all the nodes present in particular DIV element.see the below
I have a table called Review and i want to retrieve all review objects
I have loaded the entire HTML of a page and want to retrieve all
I have 2 tables, Forums and Posts. I want to retrieve all Forums fields
Say I have a sorted-set of integers, xs, and I want to retrieve all
I have a table with 116,000 rows and I want to retrieve all of

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.