XPath filter attribute with namespace -


i trying following working alas failing return expected result. although similar questions have asked before restricted being limited xpath 1.0.

i looking use xpath first text node inside "subtitle" node. xml follows:

<topic class="coverpage">     <subtitle id="idb2907ca1-51fe-472e-bf99-246126937eab">         <xt:deltext xt:action="start" xt:author="james doherty" xt:datetime="2016-01-27t17:07:00" xt:id="fb72fba6-f502-422e-9e91-1731ed007e98"/>             ignore         <xt:deltext xt:action="end" xt:id="fb72fba6-f502-422e-9e91-1731ed007e98"/>         sub-title         <xt:instext xt:action="start" xt:author="james doherty" xt:datetime="2016-01-27t14:55:00" xt:id="44ac82c2-acfc-4721-b962-20ac2b18d9f3"/>             insert additional text         <xt:instext xt:action="end" xt:id="44ac82c2-acfc-4721-b962-20ac2b18d9f3"/>         text     </subtitle> </topic> 

alternative xml provide below:

<topic class="coverpage">     sub-title     <subtitle id="idb2907ca1-51fe-472e-bf99-246126937eab">         <xt:deltext xt:action="start" xt:author="james doherty" xt:datetime="2016-01-27t17:07:00" xt:id="fb72fba6-f502-422e-9e91-1731ed007e98"/>             ignore         <xt:deltext xt:action="end" xt:id="fb72fba6-f502-422e-9e91-1731ed007e98"/>         <xt:instext xt:action="start" xt:author="james doherty" xt:datetime="2016-01-27t14:55:00" xt:id="44ac82c2-acfc-4721-b962-20ac2b18d9f3"/>             insert additional text         <xt:instext xt:action="end" xt:id="44ac82c2-acfc-4721-b962-20ac2b18d9f3"/>         text     </subtitle> </topic> 

i have tried following no luck:

/topic[@class='coverpage']/*[local-name()='subtitle']/text()[1]|/topic[@class='coverpage']/*[local-name()='subtitle']/*[substring(local-name(), string-length(local-name())-string-length('text')+1)='text'][@*[local-name()='action']='end'][1]/following-sibling::text()[1] 

i believe issue attribute value "action" , having namespace. expected results "sub-title". ideas on how can work?

the xml missing xml namespace definition, kindly pointed out @keithhall in comments of op.

<topic class="coverpage" "xmlns:xt="http://stackoverflow.com/questions/35063599/xpath-filter-attribute-with-namespace">     <subtitle id="idb2907ca1-51fe-472e-bf99-246126937eab">         <xt:deltext xt:action="start" xt:author="james doherty" xt:datetime="2016-01-27t17:07:00" xt:id="fb72fba6-f502-422e-9e91-1731ed007e98"/>             ignore         <xt:deltext xt:action="end" xt:id="fb72fba6-f502-422e-9e91-1731ed007e98"/>         sub-title         <xt:instext xt:action="start" xt:author="james doherty" xt:datetime="2016-01-27t14:55:00" xt:id="44ac82c2-acfc-4721-b962-20ac2b18d9f3"/>             insert additional text         <xt:instext xt:action="end" xt:id="44ac82c2-acfc-4721-b962-20ac2b18d9f3"/>         text     </subtitle> </topic> 

to filter xml based on attribute value, namespace, following xpath used:

[@*[local-name()='action']='end'] 

the full xpath achieve expected result below, unchanged op.

/topic[@class='coverpage']/*[local-name()='subtitle']/text()[1]|/topic[@class='coverpage']/*[local-name()='subtitle']/*[substring(local-name(), string-length(local-name())-string-length('text')+1)='text'][@*[local-name()='action']='end'][1]/following-sibling::text()[1] 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -