I'm trying to find the element by using contains.The problem is If the string contains one single quote or double quote,it's difficult to get it. I'm using this xpath to match directly to the first element.Is there a better way to implement without using 'and' statement here ?
Xpath Used :-
.//*[local-name()='GEOGRAPHY_TITLE'][contains(.,"APAC > Andaman Islands > test&'<,")and contains(., '"123')]
XML Used :-
<MST>
<MST_GEOGRAPHY >
<GEOGRAPHY_TITLE>APAC > Andaman Islands > test&'<,\"123</GEOGRAPHY_TITLE>
<GEOGRAPHY_ID>5a7a24ec-93ff-8be6-7ef9-fa021500df0e</GEOGRAPHY_ID>
<TENANT_ID>{0559cdcb-c63b-4c81-be91-b78e831bf5a5}</TENANT_ID>
<ACTIVE>1</ACTIVE>
</MST_GEOGRAPHY>
<MST_GEOGRAPHY >
<GEOGRAPHY_TITLE>APAC > Andaman Islands > test\"123&'<,\"123</GEOGRAPHY_TITLE>
<GEOGRAPHY_ID>5a7a24ec-93ff-8be6-7ef9-fa021500df0e</GEOGRAPHY_ID>
<TENANT_ID>{0559cdcb-c63b-4c81-be91-b78e831bf5a5}</TENANT_ID>
<ACTIVE>1</ACTIVE>
</MST_GEOGRAPHY>
<MST_GEOGRAPHY >
<GEOGRAPHY_TITLE>hi</GEOGRAPHY_TITLE>
<GEOGRAPHY_ID>5a7a24ec-93ff-8be6-7ef9-fa021500df0e</GEOGRAPHY_ID>
<TENANT_ID>{0559cdcb-c63b-4c81-be91-b78e831bf5a5}</TENANT_ID>
<ACTIVE>1</ACTIVE>
</MST_GEOGRAPHY>
</MST>
This may be a style thing, but I would probably rewrite your XPath to this:
In this manner the selection of the element is absolute and static rather than the evaluation of the
local-name
function, this should prove more efficient. As you are already familiar with using multiple predicates as a way of AND'ing constraints, it would seem sensible to me to also use multiple predicates for the contains rather than the 'and' keyword. Typically (but not always) if you place the most selective predicate first, you will see better performance than placing the least selective predicate first.