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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:51:03+00:00 2026-06-17T20:51:03+00:00

I have an XML with entities like this : <Entity> <Name>Lwresd_Dns_Server|LwresdDnsServer</Name> </Entity <Entity> <Name>Lwresd_Dns_Server_Data|LwresdDnsServerData</Name>

  • 0

I have an XML with entities like this :

<Entity>
    <Name>Lwresd_Dns_Server|LwresdDnsServer</Name>
 </Entity   

<Entity>
   <Name>Lwresd_Dns_Server_Data|LwresdDnsServerData</Name>
</Entity>

My xpath expression is
XPathExpression expr = xpath1.compile("//Entity[matches(Name,'" +line+ "')]");

where line is a variable with value LwresdDnsServer.

The above xpath expression matches both entities , where I need it to match only the first one, i.e

Lwresd_Dns_Server|LwresdDnsServer

How should I frame the expression to do that ??

  • 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-17T20:51:04+00:00Added an answer on June 17, 2026 at 8:51 pm

    I believe this should do the trick:

    XPathExpression expr = 
        xpath1.compile("//Entity[contains(concat('|', Name, '|'),'|" +line+ "|')]");
    

    This compares the entity Name enclosed in |s with the variable name enclosed in |s, so you get something like:

    contains('|Lwresd_Dns_Server|LwresdDnsServer|', '|LwrestDnsServer|') => Yes
    contains('|Lwresd_Dns_Server_Data|LwresdDnsServerData|', '|LwrestDnsServer|') => No
    

    And resultingly, only the first of the two Entities is selected.

    If you only want to find entities that end with line (and not just those that contain an exact match for it), then you can do this (assuming the values are guaranteed to not contain the character $ – if there’s the possibility it would contain a $, you should choose a different delimiter that it definitely won’t contain, or use Dimitre Novatchev’s answer to this question):

    XPathExpression expr = 
        xpath1.compile("//Entity[contains(concat(Name, '$'),'" +line+ "$')]");
    

    I haven’t used the matches() function in XPath (it’s not supported in XPath 1.0), but I suspect the following would also work for finding a value at the end of an Entity name, if your XPath evaluator supports matches():

    XPathExpression expr = 
        xpath1.compile("//Entity[matches(Name,'" +line+ "$')]");
    

    Here, $ is the RegEx symbol for the end of a string.

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

Sidebar

Related Questions

I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>
I have xml like this: <rule> <word>I</word> <word>need</word> <word>more</word> <marker> <word>money</word> </marker> <word>now</word> </rule>
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have map the entities in .hmb.xml and define attribute for all entity in
I have some XML that looks like this: <abc x={></abc> I want to force
I Have XML similar to this(omitted parts for brevity): <uformrecord> <state>Submitted</state> <created>2012-06-19T11:31:54</created> <updated>2012-06-19T11:32:13</updated> <id>53225sas3c1-d727-42cd-93a6-97cd778e5ee9</id>
I have XML in the form: <Books> <Book> <Name>Lord of the Rings</Name> </Book> <Book>
I have XML-structure. Context of executing XPath is one of the elements with class
I have this XML input: <?xml version=1.0 encoding=utf-8?> <string> &lt;N/A&gt; </string> Here is a

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.