xml - How to output specific values with XPathQuery? -


when do

account[@id=15] 

i get

<?xml version="1.0" encoding="utf-8"?> <root>   <account id="15" first_name="sandra" last_name="schlichting">     <private_address address_id="19" />     <profile_employee fk_id="15">       <date_created>2011-1-2t1:1:00</date_created>       <address building="3" room="2" floor="1" />     </profile_employee>     <profile_student fk_id="15">       <address address_id="19" />     </profile_student>     <profile_student fk_id="15">       <address address_id="45" />     </profile_student>   </account> </root> 

but output values of

  • first_name
  • last_name
  • building
  • room

can figure out how that?

update:

these commands works

account[@id=15]/profile_employee account[@id=15]/profile_employee/address 

but outputs entire elements, , not attributes room , building.

while @flack's answer correct, wanted result can produced single xpath expression:

concat('&#xa;', /*/account[@id=15]/@first_name,        ' ', /*/account[@id=15]/@last_name,        ' : ', /*/account[@id=15]/profile_employee/address/@building,        '/', /*/account[@id=15]/profile_employee/address/@room        ) 

when xpath expression evaluated on provided xml document:

<root>     <account id="15" first_name="sandra" last_name="schlichting">         <private_address address_id="19" />         <profile_employee fk_id="15">             <date_created>2011-1-2t1:1:00</date_created>             <address building="3" room="2" floor="1" />         </profile_employee>         <profile_student fk_id="15">             <address address_id="19" />         </profile_student>         <profile_student fk_id="15">             <address address_id="45" />         </profile_student>     </account> </root> 

the wanted, correct result produced:

sandra schlichting : 3/2 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -